3 namespace Drupal\entity\Routing;
5 use Drupal\Core\Entity\EntityTypeInterface;
6 use Drupal\Core\Entity\Routing\EntityRouteProviderInterface;
7 use Symfony\Component\Routing\Route;
8 use Symfony\Component\Routing\RouteCollection;
11 * Provides revision routes.
13 class RevisionRouteProvider implements EntityRouteProviderInterface {
18 public function getRoutes(EntityTypeInterface $entity_type) {
19 $collection = new RouteCollection();
20 $entity_type_id = $entity_type->id();
21 if ($view_route = $this->getRevisionViewRoute($entity_type)) {
22 $collection->add("entity.$entity_type_id.revision", $view_route);
24 if ($view_route = $this->getRevisionRevertRoute($entity_type)) {
25 $collection->add("entity.$entity_type_id.revision_revert_form", $view_route);
28 if ($view_route = $this->getRevisionHistoryRoute($entity_type)) {
29 $collection->add("entity.$entity_type_id.version_history", $view_route);
36 * Gets the entity revision view route.
38 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
41 * @return \Symfony\Component\Routing\Route|null
42 * The generated route, if available.
44 protected function getRevisionViewRoute(EntityTypeInterface $entity_type) {
45 if ($entity_type->hasLinkTemplate('revision')) {
46 $entity_type_id = $entity_type->id();
47 $route = new Route($entity_type->getLinkTemplate('revision'));
49 '_controller' => '\Drupal\Core\Entity\Controller\EntityViewController::viewRevision',
50 '_title_callback' => '\Drupal\Core\Entity\Controller\EntityController::title',
52 $route->addRequirements([
53 '_entity_access_revision' => "$entity_type_id.view",
55 $route->setOption('parameters', [
56 $entity_type->id() => [
57 'type' => 'entity:' . $entity_type->id(),
59 $entity_type->id() . '_revision' => [
60 'type' => 'entity_revision:' . $entity_type->id(),
68 * Gets the entity revision revert route.
70 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
73 * @return \Symfony\Component\Routing\Route|null
74 * The generated route, if available.
76 protected function getRevisionRevertRoute(EntityTypeInterface $entity_type) {
77 if ($entity_type->hasLinkTemplate('revision-revert-form')) {
78 $entity_type_id = $entity_type->id();
79 $route = new Route($entity_type->getLinkTemplate('revision-revert-form'));
81 '_form' => '\Drupal\entity\Form\RevisionRevertForm',
82 'title' => 'Revert to earlier revision',
84 $route->addRequirements([
85 '_entity_access_revision' => "$entity_type_id.update",
87 $route->setOption('parameters', [
88 $entity_type->id() => [
89 'type' => 'entity:' . $entity_type->id(),
91 $entity_type->id() . '_revision' => [
92 'type' => 'entity_revision:' . $entity_type->id(),
100 * Gets the entity revision version history route.
102 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
105 * @return \Symfony\Component\Routing\Route|null
106 * The generated route, if available.
108 protected function getRevisionHistoryRoute($entity_type) {
109 if ($entity_type->hasLinkTemplate('version-history')) {
110 $entity_type_id = $entity_type->id();
111 $route = new Route($entity_type->getLinkTemplate('version-history'));
112 $route->addDefaults([
113 '_controller' => '\Drupal\entity\Controller\RevisionOverviewController::revisionOverviewController',
114 '_title' => 'Revisions',
116 $route->setRequirement('_entity_access_revision', "$entity_type_id.list");
117 $route->setOption('entity_type_id', $entity_type->id());
118 $route->setOption('parameters', [
119 $entity_type->id() => [
120 'type' => 'entity:' . $entity_type->id(),