Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Merge requests
!2847
Issue
#2350939
: Implement a generic revision UI
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Issue
#2350939
: Implement a generic revision UI
issue/drupal-2350939:2350939-core101
into
10.1.x
Overview
25
Commits
9
Pipelines
0
Changes
28
Open
dpi
requested to merge
issue/drupal-2350939:2350939-core101
into
10.1.x
2 years ago
Overview
25
Commits
9
Pipelines
0
Changes
28
Expand
0
0
Merge request reports
Compare
10.1.x
version 7
2e8bb14e
2 years ago
version 6
a68a9a41
2 years ago
version 5
0fb7176b
2 years ago
version 4
86566f76
2 years ago
version 3
8df068f4
2 years ago
version 2
02cd6f7e
2 years ago
version 1
c03931e0
2 years ago
10.1.x (base)
and
latest version
latest version
d6ed6539
9 commits,
2 years ago
version 7
2e8bb14e
8 commits,
2 years ago
version 6
a68a9a41
6 commits,
2 years ago
version 5
0fb7176b
5 commits,
2 years ago
version 4
86566f76
4 commits,
2 years ago
version 3
8df068f4
4 commits,
2 years ago
version 2
02cd6f7e
3 commits,
2 years ago
version 1
c03931e0
2 commits,
2 years ago
28 files
+
2723
−
38
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
28
Search (e.g. *.vue) (Ctrl+P)
core/lib/Drupal/Core/Entity/Controller/EntityRevisionViewController.php
0 → 100644
+
102
−
0
Options
<?php
namespace
Drupal\Core\Entity\Controller
;
use
Drupal\Core\Datetime\DateFormatterInterface
;
use
Drupal\Core\DependencyInjection\ContainerInjectionInterface
;
use
Drupal\Core\Entity\EntityRepositoryInterface
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Entity\RevisionableInterface
;
use
Drupal\Core\Entity\RevisionLogInterface
;
use
Drupal\Core\StringTranslation\StringTranslationTrait
;
use
Drupal\Core\StringTranslation\TranslatableMarkup
;
use
Drupal\Core\StringTranslation\TranslationInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Defines a controller to view an entity revision.
*/
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
(
protected
EntityTypeManagerInterface
$entityTypeManager
,
protected
EntityRepositoryInterface
$entityRepository
,
protected
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
);
}
}
Loading