dateFormatter = $date_formatter; $this->renderer = $renderer; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static($container->get('date.formatter'), $container->get('renderer')); } /** * {@inheritdoc} */ protected function hasDeleteRevisionAccess(EntityInterface $entity) { return $this->currentUser()->hasPermission("delete all {$entity->id()} revisions"); } /** * {@inheritdoc} */ protected function buildRevertRevisionLink(EntityInterface $entity_revision) { if ($entity_revision->hasLinkTemplate('revision-revert-form')) { return [ 'title' => t('Revert'), 'url' => $entity_revision->toUrl('revision-revert-form'), ]; } } /** * {@inheritdoc} */ protected function buildDeleteRevisionLink(EntityInterface $entity_revision) { if ($entity_revision->hasLinkTemplate('revision-delete-form')) { return [ 'title' => t('Delete'), 'url' => $entity_revision->toUrl('revision-delete-form'), ]; } } /** * Generates an overview table of older revisions of an entity. * * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The route match. * * @return array * A render array. */ public function revisionOverviewController(RouteMatchInterface $route_match) { return $this->revisionOverview($route_match->getParameter($route_match->getRouteObject()->getOption('entity_type_id'))); } /** * {@inheritdoc} */ protected function getRevisionDescription(ContentEntityInterface $revision, $is_default = FALSE) { /** @var \Drupal\Core\Entity\ContentEntityInterface|\Drupal\user\EntityOwnerInterface|\Drupal\Core\Entity\RevisionLogInterface $revision */ if ($revision instanceof RevisionLogInterface) { // Use revision link to link to revisions that are not active. $date = $this->dateFormatter->format($revision->getRevisionCreationTime(), 'short'); $link = $revision->toLink($date, 'revision'); // @todo: Simplify this when https://www.drupal.org/node/2334319 lands. $username = [ '#theme' => 'username', '#account' => $revision->getRevisionUser(), ]; $username = $this->renderer->render($username); } else { $link = $revision->toLink($revision->label(), 'revision'); $username = ''; } $markup = ''; if ($revision instanceof RevisionLogInterface) { $markup = $revision->getRevisionLogMessage(); } if ($username) { $template = '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}

{{ message }}

{% endif %}'; } else { $template = '{% trans %} {{ date }} {% endtrans %}{% if message %}

{{ message }}

{% endif %}'; } $column = [ 'data' => [ '#type' => 'inline_template', '#template' => $template, '#context' => [ 'date' => $link->toString(), 'username' => $username, 'message' => ['#markup' => $markup, '#allowed_tags' => Xss::getHtmlTagList()], ], ], ]; return $column; } /** * {@inheritdoc} */ protected function hasRevertRevisionAccess(EntityInterface $entity) { return AccessResult::allowedIfHasPermission($this->currentUser(), "revert all {$entity->getEntityTypeId()} revisions")->orIf( AccessResult::allowedIfHasPermission($this->currentUser(), "revert {$entity->bundle()} {$entity->getEntityTypeId()} revisions") ); } }