class EntityRevisionViewController
Same name in other branches
- 11.x core/lib/Drupal/Core/Entity/Controller/EntityRevisionViewController.php \Drupal\Core\Entity\Controller\EntityRevisionViewController
Defines a controller to view an entity revision.
Hierarchy
- class \Drupal\Core\Entity\Controller\EntityRevisionViewController implements \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\StringTranslation\StringTranslationTrait
Expanded class hierarchy of EntityRevisionViewController
1 file declares its use of EntityRevisionViewController
- RevisionHtmlRouteProvider.php in core/
lib/ Drupal/ Core/ Entity/ Routing/ RevisionHtmlRouteProvider.php
1 string reference to 'EntityRevisionViewController'
- entity_test.routing.yml in core/
modules/ system/ tests/ modules/ entity_test/ entity_test.routing.yml - core/modules/system/tests/modules/entity_test/entity_test.routing.yml
File
-
core/
lib/ Drupal/ Core/ Entity/ Controller/ EntityRevisionViewController.php, line 19
Namespace
Drupal\Core\Entity\ControllerView source
class EntityRevisionViewController implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* Creates a new EntityRevisionViewController.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entityRepository
* The entity repository.
* @param \Drupal\Core\Datetime\DateFormatterInterface $dateFormatter
* The date formatter.
* @param \Drupal\Core\StringTranslation\TranslationInterface $translation
* The string translation manager.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager, EntityRepositoryInterface $entityRepository, DateFormatterInterface $dateFormatter, TranslationInterface $translation) {
$this->setStringTranslation($translation);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('entity_type.manager'), $container->get('entity.repository'), $container->get('date.formatter'), $container->get('string_translation'));
}
/**
* Provides a page to render a single entity revision.
*
* @param \Drupal\Core\Entity\RevisionableInterface $_entity_revision
* The Entity to be rendered. Note this variable is named $_entity_revision
* rather than $entity to prevent collisions with other named placeholders
* in the route.
* @param string $view_mode
* (optional) The view mode that should be used to display the entity.
* Defaults to 'full'.
*
* @return array
* A render array.
*/
public function __invoke(RevisionableInterface $_entity_revision, string $view_mode = 'full') : array {
$entityTypeId = $_entity_revision->getEntityTypeId();
$page = $this->entityTypeManager
->getViewBuilder($entityTypeId)
->view($_entity_revision, $view_mode);
$page['#entity_type'] = $entityTypeId;
$page['#' . $entityTypeId] = $_entity_revision;
return $page;
}
/**
* Provides a title callback for a revision of an entity.
*
* @param \Drupal\Core\Entity\RevisionableInterface $_entity_revision
* The revisionable entity, passed in directly from request attributes.
*
* @return \Drupal\Core\StringTranslation\TranslatableMarkup
* The title for the entity revision view page.
*/
public function title(RevisionableInterface $_entity_revision) : TranslatableMarkup {
$revision = $this->entityRepository
->getTranslationFromContext($_entity_revision);
$titleArgs = [
'%title' => $revision->label(),
];
if (!$revision instanceof RevisionLogInterface) {
return $this->t('Revision of %title', $titleArgs);
}
$titleArgs['%date'] = $this->dateFormatter
->format($revision->getRevisionCreationTime());
return $this->t('Revision of %title from %date', $titleArgs);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
EntityRevisionViewController::create | public static | function | Instantiates a new instance of this class. | Overrides ContainerInjectionInterface::create | |
EntityRevisionViewController::title | public | function | Provides a title callback for a revision of an entity. | ||
EntityRevisionViewController::__construct | public | function | Creates a new EntityRevisionViewController. | ||
EntityRevisionViewController::__invoke | public | function | Provides a page to render a single entity revision. | ||
StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | 3 | |
StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. | ||
StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. | ||
StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. | ||
StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. | 2 | |
StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.