function VersionHistoryController::getRevisionDescription

Same name and namespace in other branches
  1. 10 core/lib/Drupal/Core/Entity/Controller/VersionHistoryController.php \Drupal\Core\Entity\Controller\VersionHistoryController::getRevisionDescription()

Get a description of the revision.

Parameters

\Drupal\Core\Entity\RevisionableInterface $revision: The entity revision.

Return value

array A render array describing the revision.

1 call to VersionHistoryController::getRevisionDescription()
VersionHistoryController::buildRow in core/lib/Drupal/Core/Entity/Controller/VersionHistoryController.php
Builds a table row for a revision.

File

core/lib/Drupal/Core/Entity/Controller/VersionHistoryController.php, line 143

Class

VersionHistoryController
Provides a controller showing revision history for an entity.

Namespace

Drupal\Core\Entity\Controller

Code

protected function getRevisionDescription(RevisionableInterface $revision) : array {
    $context = [];
    if ($revision instanceof RevisionLogInterface) {
        // Use revision link to link to revisions that are not active.
        [
            'type' => $dateFormatType,
            'format' => $dateFormatFormat,
        ] = $this->getRevisionDescriptionDateFormat($revision);
        $linkText = $this->dateFormatter
            ->format($revision->getRevisionCreationTime(), $dateFormatType, $dateFormatFormat);
        // @todo Simplify this when https://www.drupal.org/node/2334319 lands.
        $username = [
            '#theme' => 'username',
            '#account' => $revision->getRevisionUser(),
        ];
        $context['username'] = $this->renderer
            ->render($username);
    }
    else {
        $linkText = $revision->access('view label') ? $revision->label() : $this->t('- Restricted access -');
    }
    $url = $revision->hasLinkTemplate('revision') ? $revision->toUrl('revision') : NULL;
    $context['revision'] = $url && $url->access() ? Link::fromTextAndUrl($linkText, $url)->toString() : (string) $linkText;
    $context['message'] = $revision instanceof RevisionLogInterface ? [
        '#markup' => $revision->getRevisionLogMessage(),
        '#allowed_tags' => Xss::getHtmlTagList(),
    ] : '';
    return [
        'data' => [
            '#type' => 'inline_template',
            '#template' => isset($context['username']) ? '{% trans %} {{ revision }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}' : '{% trans %} {{ revision }} {% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}',
            '#context' => $context,
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.