public function LibraryItemController::revisionOverview in Paragraphs 8
Generates an overview table of older revisions of a library item.
Parameters
\Drupal\paragraphs_library\Entity\LibraryItem $paragraphs_library_item: A library item object.
Return value
array An array as expected by drupal_render()
1 string reference to 'LibraryItemController::revisionOverview'
- paragraphs_library.routing.yml in modules/
paragraphs_library/ paragraphs_library.routing.yml - modules/paragraphs_library/paragraphs_library.routing.yml
File
- modules/
paragraphs_library/ src/ Controller/ LibraryItemController.php, line 74
Class
Namespace
Drupal\paragraphs_library\ControllerCode
public function revisionOverview(LibraryItem $paragraphs_library_item) {
$label = $paragraphs_library_item
->get('label')->value;
$build['#title'] = $this
->t('Revisions for %label', [
'%label' => $label,
]);
$header = [
$this
->t('Revision'),
$this
->t('Operations'),
];
$rows = [];
$default_revision = $paragraphs_library_item
->getRevisionId();
$storage = $this->entityTypeManager
->getStorage('paragraphs_library_item');
foreach ($this
->getRevisionIds($paragraphs_library_item) as $revision_id) {
$revision = $storage
->loadRevision($revision_id);
$date = $this->dateFormatter
->format($revision
->get('revision_created')->value, 'short');
$row = [];
$username = [
'#theme' => 'username',
'#account' => $revision
->getRevisionUser(),
];
$column = [
'data' => [
'#type' => 'inline_template',
'#template' => '{% trans %}{{ date }}: {{ label }} by {{ author }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}',
'#context' => [
'date' => $revision
->toLink($date, $revision
->isDefaultRevision() ? 'canonical' : 'revision')
->toString(),
'label' => $revision
->label(),
'author' => $this->renderer
->renderPlain($username),
'message' => [
'#markup' => $revision
->get('revision_log')->value,
'#allowed_tags' => Xss::getHtmlTagList(),
],
],
],
];
$row[] = $column;
if ($revision_id == $default_revision) {
$row[] = [
'data' => [
'#prefix' => '<em>',
'#markup' => $this
->t('Current revision'),
'#suffix' => '</em>',
],
];
$rows[] = [
'data' => $row,
'class' => [
'revision-current',
],
];
}
else {
$links = [
'revert' => [
'title' => $revision_id < $paragraphs_library_item
->getRevisionId() ? $this
->t('Revert') : $this
->t('Set as current revision'),
'url' => $revision
->toUrl('revision-revert'),
],
'delete' => [
'title' => $this
->t('Delete'),
'url' => $revision
->toUrl('revision-delete'),
],
];
$row[] = [
'data' => [
'#type' => 'operations',
'#links' => $links,
],
];
$rows[] = $row;
}
}
$build['paragraphs_library_item_revisions_table'] = [
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
];
$build['pager'] = [
'#type' => 'pager',
];
return $build;
}