function VersionHistoryController::loadRevisions
Same name in other branches
- 11.x core/lib/Drupal/Core/Entity/Controller/VersionHistoryController.php \Drupal\Core\Entity\Controller\VersionHistoryController::loadRevisions()
Generates revisions of an entity relevant to the current language.
Parameters
\Drupal\Core\Entity\RevisionableInterface $entity: The entity.
Return value
\Generator|\Drupal\Core\Entity\RevisionableInterface Generates revisions.
1 call to VersionHistoryController::loadRevisions()
- VersionHistoryController::revisionOverview in core/
lib/ Drupal/ Core/ Entity/ Controller/ VersionHistoryController.php - Generates an overview table of revisions of an entity.
File
-
core/
lib/ Drupal/ Core/ Entity/ Controller/ VersionHistoryController.php, line 207
Class
- VersionHistoryController
- Provides a controller showing revision history for an entity.
Namespace
Drupal\Core\Entity\ControllerCode
protected function loadRevisions(RevisionableInterface $entity) {
$entityType = $entity->getEntityType();
$translatable = $entityType->isTranslatable();
$entityStorage = $this->entityTypeManager
->getStorage($entity->getEntityTypeId());
assert($entityStorage instanceof RevisionableStorageInterface);
$result = $entityStorage->getQuery()
->accessCheck(FALSE)
->allRevisions()
->condition($entityType->getKey('id'), $entity->id())
->sort($entityType->getKey('revision'), 'DESC')
->pager(self::REVISIONS_PER_PAGE)
->execute();
$currentLangcode = $this->languageManager
->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
->getId();
foreach ($entityStorage->loadMultipleRevisions(array_keys($result)) as $revision) {
// Only show revisions that are affected by the language that is being
// displayed.
if (!$translatable || $revision->hasTranslation($currentLangcode) && $revision->getTranslation($currentLangcode)
->isRevisionTranslationAffected()) {
(yield $translatable ? $revision->getTranslation($currentLangcode) : $revision);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.