class RevisionOverviewController in Entity API 8
Same name and namespace in other branches
- 8.0 src/Controller/RevisionOverviewController.php \Drupal\entity\Controller\RevisionOverviewController
Provides a controller which shows the revision history.
This controller leverages the revision controller trait, which is agnostic to any entity type, by using \Drupal\Core\Entity\RevisionLogInterface.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\entity\Controller\RevisionOverviewController uses RevisionControllerTrait
Expanded class hierarchy of RevisionOverviewController
File
- src/
Controller/ RevisionOverviewController.php, line 22
Namespace
Drupal\entity\ControllerView source
class RevisionOverviewController extends ControllerBase {
use RevisionControllerTrait;
/**
* The date formatter.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;
/**
* The renderer.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* Creates a new RevisionOverviewController instance.
*
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter.
*/
public function __construct(DateFormatterInterface $date_formatter, RendererInterface $renderer) {
$this->dateFormatter = $date_formatter;
$this->renderer = $renderer;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('date.formatter'), $container
->get('renderer'));
}
/**
* {@inheritdoc}
*/
protected function hasDeleteRevisionAccess(EntityInterface $entity) {
return $this
->currentUser()
->hasPermission("delete all {$entity->getEntityTypeId()} revisions");
}
/**
* {@inheritdoc}
*/
protected function buildRevertRevisionLink(EntityInterface $entity_revision) {
if ($entity_revision
->hasLinkTemplate('revision-revert-form')) {
return [
'title' => $this
->t('Revert'),
'url' => $entity_revision
->toUrl('revision-revert-form'),
];
}
}
/**
* {@inheritdoc}
*/
protected function buildDeleteRevisionLink(EntityInterface $entity_revision) {
if ($entity_revision
->hasLinkTemplate('revision-delete-form')) {
return [
'title' => $this
->t('Delete'),
'url' => $entity_revision
->toUrl('revision-delete-form'),
];
}
}
/**
* Generates an overview table of older revisions of an entity.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*
* @return array
* A render array.
*/
public function revisionOverviewController(RouteMatchInterface $route_match) {
return $this
->revisionOverview($route_match
->getParameter($route_match
->getRouteObject()
->getOption('entity_type_id')));
}
/**
* {@inheritdoc}
*/
protected function getRevisionDescription(ContentEntityInterface $revision, $is_default = FALSE) {
/** @var \Drupal\Core\Entity\ContentEntityInterface|\Drupal\user\EntityOwnerInterface|\Drupal\Core\Entity\RevisionLogInterface $revision */
if ($revision instanceof RevisionLogInterface) {
// Use revision link to link to revisions that are not active.
$date = $this->dateFormatter
->format($revision
->getRevisionCreationTime(), 'short');
$link = $revision
->toLink($date, 'revision');
// @todo: Simplify this when https://www.drupal.org/node/2334319 lands.
$username = [
'#theme' => 'username',
'#account' => $revision
->getRevisionUser(),
];
$username = $this->renderer
->render($username);
}
else {
$link = $revision
->toLink($revision
->label(), 'revision');
$username = '';
}
$markup = '';
if ($revision instanceof RevisionLogInterface) {
$markup = $revision
->getRevisionLogMessage();
}
if ($username) {
$template = '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}';
}
else {
$template = '{% trans %} {{ date }} {% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}';
}
$column = [
'data' => [
'#type' => 'inline_template',
'#template' => $template,
'#context' => [
'date' => $link
->toString(),
'username' => $username,
'message' => [
'#markup' => $markup,
'#allowed_tags' => Xss::getHtmlTagList(),
],
],
],
];
return $column;
}
/**
* {@inheritdoc}
*/
protected function hasRevertRevisionAccess(EntityInterface $entity) {
return AccessResult::allowedIfHasPermission($this
->currentUser(), "revert all {$entity->getEntityTypeId()} revisions")
->orIf(AccessResult::allowedIfHasPermission($this
->currentUser(), "revert {$entity->bundle()} {$entity->getEntityTypeId()} revisions"));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
RevisionControllerTrait:: |
abstract protected | function | Returns the entity type manager. | |
RevisionControllerTrait:: |
protected | function | Get the links of the operations for an entity revision. | |
RevisionControllerTrait:: |
abstract public | function | Returns the langauge manager. | |
RevisionControllerTrait:: |
protected | function | Loads all revision IDs of an entity sorted by revision ID descending. | |
RevisionControllerTrait:: |
protected | function | Generates an overview table of older revisions of an entity. | |
RevisionOverviewController:: |
protected | property | The date formatter. | |
RevisionOverviewController:: |
protected | property | The renderer. | |
RevisionOverviewController:: |
protected | function |
Builds a link to delete an entity revision. Overrides RevisionControllerTrait:: |
|
RevisionOverviewController:: |
protected | function |
Builds a link to revert an entity revision. Overrides RevisionControllerTrait:: |
|
RevisionOverviewController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
RevisionOverviewController:: |
protected | function |
Returns a string providing details of the revision. Overrides RevisionControllerTrait:: |
|
RevisionOverviewController:: |
protected | function |
Determines if the user has permission to delete revisions. Overrides RevisionControllerTrait:: |
|
RevisionOverviewController:: |
protected | function |
Determines if the user has permission to revert revisions. Overrides RevisionControllerTrait:: |
|
RevisionOverviewController:: |
public | function | Generates an overview table of older revisions of an entity. | |
RevisionOverviewController:: |
public | function | Creates a new RevisionOverviewController instance. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |