Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / entity / src / Routing / RevisionRouteProvider.php
1 <?php
2
3 namespace Drupal\entity\Routing;
4
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;
9
10 /**
11  * Provides revision routes.
12  */
13 class RevisionRouteProvider implements EntityRouteProviderInterface {
14
15   /**
16    * {@inheritdoc}
17    */
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);
23     }
24     if ($view_route = $this->getRevisionRevertRoute($entity_type)) {
25       $collection->add("entity.$entity_type_id.revision_revert_form", $view_route);
26     }
27
28     if ($view_route = $this->getRevisionHistoryRoute($entity_type)) {
29       $collection->add("entity.$entity_type_id.version_history", $view_route);
30     }
31
32     return $collection;
33   }
34
35   /**
36    * Gets the entity revision view route.
37    *
38    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
39    *   The entity type.
40    *
41    * @return \Symfony\Component\Routing\Route|null
42    *   The generated route, if available.
43    */
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'));
48       $route->addDefaults([
49         '_controller' => '\Drupal\Core\Entity\Controller\EntityViewController::viewRevision',
50         '_title_callback' => '\Drupal\Core\Entity\Controller\EntityController::title',
51       ]);
52       $route->addRequirements([
53         '_entity_access_revision' => "$entity_type_id.view",
54       ]);
55       $route->setOption('parameters', [
56         $entity_type->id() => [
57           'type' => 'entity:' . $entity_type->id(),
58         ],
59         $entity_type->id() . '_revision' => [
60           'type' => 'entity_revision:' . $entity_type->id(),
61         ],
62       ]);
63       return $route;
64     }
65   }
66
67   /**
68    * Gets the entity revision revert route.
69    *
70    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
71    *   The entity type.
72    *
73    * @return \Symfony\Component\Routing\Route|null
74    *   The generated route, if available.
75    */
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'));
80       $route->addDefaults([
81         '_form' => '\Drupal\entity\Form\RevisionRevertForm',
82         'title' => 'Revert to earlier revision',
83       ]);
84       $route->addRequirements([
85         '_entity_access_revision' => "$entity_type_id.update",
86       ]);
87       $route->setOption('parameters', [
88         $entity_type->id() => [
89           'type' => 'entity:' . $entity_type->id(),
90         ],
91         $entity_type->id() . '_revision' => [
92           'type' => 'entity_revision:' . $entity_type->id(),
93         ],
94       ]);
95       return $route;
96     }
97   }
98
99   /**
100    * Gets the entity revision version history route.
101    *
102    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
103    *   The entity type.
104    *
105    * @return \Symfony\Component\Routing\Route|null
106    *   The generated route, if available.
107    */
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',
115       ]);
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(),
121         ],
122       ]);
123       return $route;
124     }
125   }
126
127 }