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;
/**
'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();
}
}
$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.
}
}
+ /**
+ * 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.
*