Mercurial > hg > isophonics-drupal-site
diff core/lib/Drupal/Core/Entity/EntityViewBuilder.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 7a779792577d |
children | c2387f117808 |
line wrap: on
line diff
--- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php Mon Apr 23 09:33:26 2018 +0100 +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php Mon Apr 23 09:46:53 2018 +0100 @@ -11,7 +11,7 @@ use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Render\Element; use Drupal\Core\Theme\Registry; -use Drupal\Core\TypedData\TranslatableInterface; +use Drupal\Core\TypedData\TranslatableInterface as TranslatableDataInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -189,7 +189,7 @@ 'bin' => $this->cacheBin, ]; - if ($entity instanceof TranslatableInterface && count($entity->getTranslationLanguages()) > 1) { + if ($entity instanceof TranslatableDataInterface && count($entity->getTranslationLanguages()) > 1) { $build['#cache']['keys'][] = $entity->language()->getId(); } } @@ -269,6 +269,7 @@ $this->moduleHandler()->invokeAll($view_hook, [&$build_list[$key], $entity, $display, $view_mode]); $this->moduleHandler()->invokeAll('entity_view', [&$build_list[$key], $entity, $display, $view_mode]); + $this->addContextualLinks($build_list[$key], $entity); $this->alterBuild($build_list[$key], $entity, $display, $view_mode); // Assign the weights configured in the display. @@ -325,6 +326,36 @@ } /** + * Add contextual links. + * + * @param array $build + * The render array that is being created. + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity to be prepared. + */ + protected function addContextualLinks(array &$build, EntityInterface $entity) { + if ($entity->isNew()) { + return; + } + $key = $entity->getEntityTypeId(); + $rel = 'canonical'; + if ($entity instanceof ContentEntityInterface && !$entity->isDefaultRevision()) { + $rel = 'revision'; + $key .= '_revision'; + } + if ($entity->hasLinkTemplate($rel)) { + $build['#contextual_links'][$key] = [ + 'route_parameters' => $entity->toUrl($rel)->getRouteParameters(), + ]; + if ($entity instanceof EntityChangedInterface) { + $build['#contextual_links'][$key]['metadata'] = [ + 'changed' => $entity->getChangedTime(), + ]; + } + } + } + + /** * Specific per-entity building. * * @param array $build