protected function RevisionOverviewController::getRevisionDescription in Entity API 8
Same name and namespace in other branches
- 8.0 src/Controller/RevisionOverviewController.php \Drupal\entity\Controller\RevisionOverviewController::getRevisionDescription()
Returns a string providing details of the revision.
E.g. Node describes its revisions using {date} by {username}. For the non-current revision, it also provides a link to view that revision.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $revision: The entity revision.
bool $is_current: TRUE if the revision is the current revision.
Return value
string Returns a string to provide the details of the revision.
Overrides RevisionControllerTrait::getRevisionDescription
File
- src/
Controller/ RevisionOverviewController.php, line 105
Class
- RevisionOverviewController
- Provides a controller which shows the revision history.
Namespace
Drupal\entity\ControllerCode
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 %}<p class="revision-log">{{ message }}</p>{% endif %}';
}
else {
$template = '{% trans %} {{ date }} {% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}';
}
$column = [
'data' => [
'#type' => 'inline_template',
'#template' => $template,
'#context' => [
'date' => $link
->toString(),
'username' => $username,
'message' => [
'#markup' => $markup,
'#allowed_tags' => Xss::getHtmlTagList(),
],
],
],
];
return $column;
}