Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / templates / module / src / entity-content-route-provider.php.twig
1 {% extends "base/class.php.twig" %}
2
3 {% block file_path %}
4 \Drupal\{{ module }}\{{ entity_class }}HtmlRouteProvider.
5 {% endblock %}
6
7 {% block namespace_class %}
8 namespace Drupal\{{ module }};
9 {% endblock %}
10
11 {% block use_class %}
12 use Drupal\Core\Entity\EntityTypeInterface;
13 use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
14 use Symfony\Component\Routing\Route;
15 {% endblock %}
16
17 {% block class_declaration %}
18 /**
19  * Provides routes for {{ label }} entities.
20  *
21  * @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
22  * @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
23  */
24 class {{ entity_class }}HtmlRouteProvider extends AdminHtmlRouteProvider {% endblock %}
25 {% block class_methods %}
26   /**
27    * {@inheritdoc}
28    */
29   public function getRoutes(EntityTypeInterface $entity_type) {
30     $collection = parent::getRoutes($entity_type);
31
32     $entity_type_id = $entity_type->id();
33 {% if revisionable %}
34
35     if ($history_route = $this->getHistoryRoute($entity_type)) {
36       $collection->add("entity.{$entity_type_id}.version_history", $history_route);
37     }
38
39     if ($revision_route = $this->getRevisionRoute($entity_type)) {
40       $collection->add("entity.{$entity_type_id}.revision", $revision_route);
41     }
42
43     if ($revert_route = $this->getRevisionRevertRoute($entity_type)) {
44       $collection->add("entity.{$entity_type_id}.revision_revert", $revert_route);
45     }
46
47     if ($delete_route = $this->getRevisionDeleteRoute($entity_type)) {
48       $collection->add("entity.{$entity_type_id}.revision_delete", $delete_route);
49     }
50 {% if is_translatable %}
51
52     if ($translation_route = $this->getRevisionTranslationRevertRoute($entity_type)) {
53       $collection->add("{$entity_type_id}.revision_revert_translation_confirm", $translation_route);
54     }
55 {%  endif %}
56 {%  endif %}
57
58     if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) {
59       $collection->add("$entity_type_id.settings", $settings_form_route);
60     }
61
62     return $collection;
63   }
64 {% if revisionable %}
65
66   /**
67    * Gets the version history route.
68    *
69    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
70    *   The entity type.
71    *
72    * @return \Symfony\Component\Routing\Route|null
73    *   The generated route, if available.
74    */
75   protected function getHistoryRoute(EntityTypeInterface $entity_type) {
76     if ($entity_type->hasLinkTemplate('version-history')) {
77       $route = new Route($entity_type->getLinkTemplate('version-history'));
78       $route
79         ->setDefaults([
80           '_title' => "{$entity_type->getLabel()} revisions",
81           '_controller' => '\Drupal\{{ module }}\Controller\{{ entity_class }}Controller::revisionOverview',
82         ])
83         ->setRequirement('_permission', 'access {{ label|lower }} revisions')
84         ->setOption('_admin_route', TRUE);
85
86       return $route;
87     }
88   }
89
90   /**
91    * Gets the revision route.
92    *
93    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
94    *   The entity type.
95    *
96    * @return \Symfony\Component\Routing\Route|null
97    *   The generated route, if available.
98    */
99   protected function getRevisionRoute(EntityTypeInterface $entity_type) {
100     if ($entity_type->hasLinkTemplate('revision')) {
101       $route = new Route($entity_type->getLinkTemplate('revision'));
102       $route
103         ->setDefaults([
104           '_controller' => '\Drupal\{{ module }}\Controller\{{ entity_class }}Controller::revisionShow',
105           '_title_callback' => '\Drupal\{{ module }}\Controller\{{ entity_class }}Controller::revisionPageTitle',
106         ])
107         ->setRequirement('_permission', 'access {{ label|lower }} revisions')
108         ->setOption('_admin_route', TRUE);
109
110       return $route;
111     }
112   }
113
114   /**
115    * Gets the revision revert route.
116    *
117    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
118    *   The entity type.
119    *
120    * @return \Symfony\Component\Routing\Route|null
121    *   The generated route, if available.
122    */
123   protected function getRevisionRevertRoute(EntityTypeInterface $entity_type) {
124     if ($entity_type->hasLinkTemplate('revision_revert')) {
125       $route = new Route($entity_type->getLinkTemplate('revision_revert'));
126       $route
127         ->setDefaults([
128           '_form' => '\Drupal\{{ module }}\Form\{{ entity_class }}RevisionRevertForm',
129           '_title' => 'Revert to earlier revision',
130         ])
131         ->setRequirement('_permission', 'revert all {{ label|lower }} revisions')
132         ->setOption('_admin_route', TRUE);
133
134       return $route;
135     }
136   }
137
138   /**
139    * Gets the revision delete route.
140    *
141    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
142    *   The entity type.
143    *
144    * @return \Symfony\Component\Routing\Route|null
145    *   The generated route, if available.
146    */
147   protected function getRevisionDeleteRoute(EntityTypeInterface $entity_type) {
148     if ($entity_type->hasLinkTemplate('revision_delete')) {
149       $route = new Route($entity_type->getLinkTemplate('revision_delete'));
150       $route
151         ->setDefaults([
152           '_form' => '\Drupal\{{ module }}\Form\{{ entity_class }}RevisionDeleteForm',
153           '_title' => 'Delete earlier revision',
154         ])
155         ->setRequirement('_permission', 'delete all {{ label|lower }} revisions')
156         ->setOption('_admin_route', TRUE);
157
158       return $route;
159     }
160   }
161 {% if is_translatable %}
162
163   /**
164    * Gets the revision translation revert route.
165    *
166    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
167    *   The entity type.
168    *
169    * @return \Symfony\Component\Routing\Route|null
170    *   The generated route, if available.
171    */
172   protected function getRevisionTranslationRevertRoute(EntityTypeInterface $entity_type) {
173     if ($entity_type->hasLinkTemplate('translation_revert')) {
174       $route = new Route($entity_type->getLinkTemplate('translation_revert'));
175       $route
176         ->setDefaults([
177           '_form' => '\Drupal\{{ module }}\Form\{{ entity_class }}RevisionRevertTranslationForm',
178           '_title' => 'Revert to earlier revision of a translation',
179         ])
180         ->setRequirement('_permission', 'revert all {{ label|lower }} revisions')
181         ->setOption('_admin_route', TRUE);
182
183       return $route;
184     }
185   }
186 {%  endif %}
187 {%  endif %}
188
189   /**
190    * Gets the settings form route.
191    *
192    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
193    *   The entity type.
194    *
195    * @return \Symfony\Component\Routing\Route|null
196    *   The generated route, if available.
197    */
198   protected function getSettingsFormRoute(EntityTypeInterface $entity_type) {
199     if (!$entity_type->getBundleEntityType()) {
200       $route = new Route("/admin/structure/{$entity_type->id()}/settings");
201       $route
202         ->setDefaults([
203           '_form' => 'Drupal\{{ module }}\Form\{{ entity_class }}SettingsForm',
204           '_title' => "{$entity_type->getLabel()} settings",
205         ])
206         ->setRequirement('_permission', $entity_type->getAdminPermission())
207         ->setOption('_admin_route', TRUE);
208
209       return $route;
210     }
211   }
212 {% endblock %}