Yaffs site version 1.1
[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
34     if ($collection_route = $this->getCollectionRoute($entity_type)) {
35       $collection->add("entity.{$entity_type_id}.collection", $collection_route);
36     }
37 {% if revisionable %}
38
39     if ($history_route = $this->getHistoryRoute($entity_type)) {
40       $collection->add("entity.{$entity_type_id}.version_history", $history_route);
41     }
42
43     if ($revision_route = $this->getRevisionRoute($entity_type)) {
44       $collection->add("entity.{$entity_type_id}.revision", $revision_route);
45     }
46
47     if ($revert_route = $this->getRevisionRevertRoute($entity_type)) {
48       $collection->add("entity.{$entity_type_id}.revision_revert", $revert_route);
49     }
50
51     if ($delete_route = $this->getRevisionDeleteRoute($entity_type)) {
52       $collection->add("entity.{$entity_type_id}.revision_delete", $delete_route);
53     }
54 {% if is_translatable %}
55
56     if ($translation_route = $this->getRevisionTranslationRevertRoute($entity_type)) {
57       $collection->add("{$entity_type_id}.revision_revert_translation_confirm", $translation_route);
58     }
59 {%  endif %}
60 {%  endif %}
61
62     if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) {
63       $collection->add("$entity_type_id.settings", $settings_form_route);
64     }
65
66     return $collection;
67   }
68
69   /**
70    * Gets the collection route.
71    *
72    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
73    *   The entity type.
74    *
75    * @return \Symfony\Component\Routing\Route|null
76    *   The generated route, if available.
77    */
78   protected function getCollectionRoute(EntityTypeInterface $entity_type) {
79     if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass()) {
80       $entity_type_id = $entity_type->id();
81       $route = new Route($entity_type->getLinkTemplate('collection'));
82       $route
83         ->setDefaults([
84           '_entity_list' => $entity_type_id,
85           '_title' => "{$entity_type->getLabel()} list",
86         ])
87         ->setRequirement('_permission', 'access {{ label|lower }} overview')
88         ->setOption('_admin_route', TRUE);
89
90       return $route;
91     }
92   }
93 {% if revisionable %}
94
95   /**
96    * Gets the version history route.
97    *
98    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
99    *   The entity type.
100    *
101    * @return \Symfony\Component\Routing\Route|null
102    *   The generated route, if available.
103    */
104   protected function getHistoryRoute(EntityTypeInterface $entity_type) {
105     if ($entity_type->hasLinkTemplate('version-history')) {
106       $route = new Route($entity_type->getLinkTemplate('version-history'));
107       $route
108         ->setDefaults([
109           '_title' => "{$entity_type->getLabel()} revisions",
110           '_controller' => '\Drupal\{{ module }}\Controller\{{ entity_class }}Controller::revisionOverview',
111         ])
112         ->setRequirement('_permission', 'access {{ label|lower }} revisions')
113         ->setOption('_admin_route', TRUE);
114
115       return $route;
116     }
117   }
118
119   /**
120    * Gets the revision route.
121    *
122    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
123    *   The entity type.
124    *
125    * @return \Symfony\Component\Routing\Route|null
126    *   The generated route, if available.
127    */
128   protected function getRevisionRoute(EntityTypeInterface $entity_type) {
129     if ($entity_type->hasLinkTemplate('revision')) {
130       $route = new Route($entity_type->getLinkTemplate('revision'));
131       $route
132         ->setDefaults([
133           '_controller' => '\Drupal\{{ module }}\Controller\{{ entity_class }}Controller::revisionShow',
134           '_title_callback' => '\Drupal\{{ module }}\Controller\{{ entity_class }}Controller::revisionPageTitle',
135         ])
136         ->setRequirement('_permission', 'access {{ label|lower }} revisions')
137         ->setOption('_admin_route', TRUE);
138
139       return $route;
140     }
141   }
142
143   /**
144    * Gets the revision revert route.
145    *
146    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
147    *   The entity type.
148    *
149    * @return \Symfony\Component\Routing\Route|null
150    *   The generated route, if available.
151    */
152   protected function getRevisionRevertRoute(EntityTypeInterface $entity_type) {
153     if ($entity_type->hasLinkTemplate('revision_revert')) {
154       $route = new Route($entity_type->getLinkTemplate('revision_revert'));
155       $route
156         ->setDefaults([
157           '_form' => '\Drupal\{{ module }}\Form\{{ entity_class }}RevisionRevertForm',
158           '_title' => 'Revert to earlier revision',
159         ])
160         ->setRequirement('_permission', 'revert all {{ label|lower }} revisions')
161         ->setOption('_admin_route', TRUE);
162
163       return $route;
164     }
165   }
166
167   /**
168    * Gets the revision delete route.
169    *
170    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
171    *   The entity type.
172    *
173    * @return \Symfony\Component\Routing\Route|null
174    *   The generated route, if available.
175    */
176   protected function getRevisionDeleteRoute(EntityTypeInterface $entity_type) {
177     if ($entity_type->hasLinkTemplate('revision_delete')) {
178       $route = new Route($entity_type->getLinkTemplate('revision_delete'));
179       $route
180         ->setDefaults([
181           '_form' => '\Drupal\{{ module }}\Form\{{ entity_class }}RevisionDeleteForm',
182           '_title' => 'Delete earlier revision',
183         ])
184         ->setRequirement('_permission', 'delete all {{ label|lower }} revisions')
185         ->setOption('_admin_route', TRUE);
186
187       return $route;
188     }
189   }
190 {% if is_translatable %}
191
192   /**
193    * Gets the revision translation revert route.
194    *
195    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
196    *   The entity type.
197    *
198    * @return \Symfony\Component\Routing\Route|null
199    *   The generated route, if available.
200    */
201   protected function getRevisionTranslationRevertRoute(EntityTypeInterface $entity_type) {
202     if ($entity_type->hasLinkTemplate('translation_revert')) {
203       $route = new Route($entity_type->getLinkTemplate('translation_revert'));
204       $route
205         ->setDefaults([
206           '_form' => '\Drupal\{{ module }}\Form\{{ entity_class }}RevisionRevertTranslationForm',
207           '_title' => 'Revert to earlier revision of a translation',
208         ])
209         ->setRequirement('_permission', 'revert all {{ label|lower }} revisions')
210         ->setOption('_admin_route', TRUE);
211
212       return $route;
213     }
214   }
215 {%  endif %}
216 {%  endif %}
217
218   /**
219    * Gets the settings form route.
220    *
221    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
222    *   The entity type.
223    *
224    * @return \Symfony\Component\Routing\Route|null
225    *   The generated route, if available.
226    */
227   protected function getSettingsFormRoute(EntityTypeInterface $entity_type) {
228     if (!$entity_type->getBundleEntityType()) {
229       $route = new Route("/admin/structure/{$entity_type->id()}/settings");
230       $route
231         ->setDefaults([
232           '_form' => 'Drupal\{{ module }}\Form\{{ entity_class }}SettingsForm',
233           '_title' => "{$entity_type->getLabel()} settings",
234         ])
235         ->setRequirement('_permission', $entity_type->getAdminPermission())
236         ->setOption('_admin_route', TRUE);
237
238       return $route;
239     }
240   }
241 {% endblock %}