protected function RevisionControllerTrait::revisionOverview in Entity API 8
Same name and namespace in other branches
- 8.0 src/Controller/RevisionControllerTrait.php \Drupal\entity\Controller\RevisionControllerTrait::revisionOverview()
Generates an overview table of older revisions of an entity.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: An entity object.
Return value
array A render array.
1 call to RevisionControllerTrait::revisionOverview()
- RevisionOverviewController::revisionOverviewController in src/
Controller/ RevisionOverviewController.php - Generates an overview table of older revisions of an entity.
File
- src/
Controller/ RevisionControllerTrait.php, line 115
Class
- RevisionControllerTrait
- Defines a trait for common revision UI functionality.
Namespace
Drupal\entity\ControllerCode
protected function revisionOverview(ContentEntityInterface $entity) {
$langcode = $this
->languageManager()
->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
->getId();
/** @var \Drupal\Core\Entity\ContentEntityStorageInterface $entity_storage */
$entity_storage = $this
->entityTypeManager()
->getStorage($entity
->getEntityTypeId());
$revision_ids = $this
->revisionIds($entity);
$entity_revisions = $entity_storage
->loadMultipleRevisions($revision_ids);
$translatable = $entity
->getEntityType()
->isTranslatable();
$header = [
$this
->t('Revision'),
$this
->t('Operations'),
];
$rows = [];
foreach ($entity_revisions as $revision) {
$row = [];
/** @var \Drupal\Core\Entity\ContentEntityInterface $revision */
if (!$translatable || $revision
->hasTranslation($langcode) && $revision
->getTranslation($langcode)
->isRevisionTranslationAffected()) {
$row[] = $this
->getRevisionDescription($revision, $revision
->isDefaultRevision());
if ($revision
->isDefaultRevision()) {
$row[] = [
'data' => [
'#prefix' => '<em>',
'#markup' => $this
->t('Current revision'),
'#suffix' => '</em>',
],
];
foreach ($row as &$current) {
$current['class'] = [
'revision-current',
];
}
}
else {
$links = $this
->getOperationLinks($revision);
$row[] = [
'data' => [
'#type' => 'operations',
'#links' => $links,
],
];
}
}
$rows[] = $row;
}
$build[$entity
->getEntityTypeId() . '_revisions_table'] = [
'#theme' => 'table',
'#rows' => $rows,
'#header' => $header,
];
// We have no clue about caching yet.
$build['#cache']['max-age'] = 0;
return $build;
}