getEntityType(); $result = $this->entityTypeManager()->getStorage($entity_type->id())->getQuery() ->allRevisions() ->condition($entity_type->getKey('id'), $entity->id()) ->sort($entity_type->getKey('revision'), 'DESC') ->execute(); return array_keys($result); } /** * Generates an overview table of older revisions of an entity. * * @param \Drupal\Core\Entity\ContentEntityInterface $entity * An entity object. * * @return array * A render array. */ 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); $header = [$this->t('Revision'), $this->t('Operations')]; $rows = []; 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' => '', '#markup' => $this->t('Current revision'), '#suffix' => '', ], ]; 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; } /** * Get the links of the operations for an entity revision. * * @param \Drupal\Core\Entity\EntityInterface $entity_revision * The entity to build the revision links for. * * @return array * The operation links. */ protected function getOperationLinks(EntityInterface $entity_revision) { $links = []; if ($this->hasRevertRevisionAccess($entity_revision)) { $links['revert'] = $this->buildRevertRevisionLink($entity_revision); } if ($this->hasDeleteRevisionAccess($entity_revision)) { $links['delete'] = $this->buildDeleteRevisionLink($entity_revision); } return array_filter($links); } }