function VersionHistoryController::loadRevisions
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Entity/Controller/VersionHistoryController.php \Drupal\Core\Entity\Controller\VersionHistoryController::loadRevisions()
- 10 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);
$query = $entityStorage->getQuery()
->accessCheck(FALSE)
->allRevisions()
->condition($entityType->getKey('id'), $entity->id())
->sort($entityType->getKey('revision'), 'DESC')
->pager(self::REVISIONS_PER_PAGE);
// Only show revisions that are affected by the language that is being
// displayed.
if ($translatable) {
$query->condition($entityType->getKey('langcode'), $entity->language()
->getId())
->condition($entityType->getKey('revision_translation_affected'), '1');
}
$result = $query->execute();
$currentLangcode = $this->languageManager
->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
->getId();
foreach ($entityStorage->loadMultipleRevisions(array_keys($result)) as $revision) {
yield $translatable ? $revision->getTranslation($currentLangcode) : $revision;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.