protected function RevisionControllerTrait::revisionOverview in Entity API 8.0
Same name and namespace in other branches
- 8 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 121 - Contains \Drupal\entity\Controller\RevisionControllerTrait.
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();
$entity_storage = $this
->entityTypeManager()
->getStorage($entity
->getEntityTypeId());
$header = [
$this
->t('Revision'),
$this
->t('Operations'),
];
$rows = [];
$revision_ids = $this
->revisionIds($entity);
// @todo Expand the entity storage to load multiple revisions.
$entity_revisions = array_combine($revision_ids, array_map(function ($vid) use ($entity_storage) {
return $entity_storage
->loadRevision($vid);
}, $revision_ids));
foreach ($entity_revisions as $revision) {
$row = [];
/** @var \Drupal\Core\Entity\ContentEntityInterface $revision */
if ($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 {
$row[] = $this
->getOperationLinks($revision);
}
}
$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;
}