1 {% extends "base/class.php.twig" %}
4 \Drupal\{{ module }}\{{ entity_class }}HtmlRouteProvider.
7 {% block namespace_class %}
8 namespace Drupal\{{ module }};
12 use Drupal\Core\Entity\EntityTypeInterface;
13 use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
14 use Symfony\Component\Routing\Route;
17 {% block class_declaration %}
19 * Provides routes for {{ label }} entities.
21 * @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
22 * @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
24 class {{ entity_class }}HtmlRouteProvider extends AdminHtmlRouteProvider {% endblock %}
25 {% block class_methods %}
29 public function getRoutes(EntityTypeInterface $entity_type) {
30 $collection = parent::getRoutes($entity_type);
32 $entity_type_id = $entity_type->id();
34 if ($collection_route = $this->getCollectionRoute($entity_type)) {
35 $collection->add("entity.{$entity_type_id}.collection", $collection_route);
39 if ($history_route = $this->getHistoryRoute($entity_type)) {
40 $collection->add("entity.{$entity_type_id}.version_history", $history_route);
43 if ($revision_route = $this->getRevisionRoute($entity_type)) {
44 $collection->add("entity.{$entity_type_id}.revision", $revision_route);
47 if ($revert_route = $this->getRevisionRevertRoute($entity_type)) {
48 $collection->add("entity.{$entity_type_id}.revision_revert", $revert_route);
51 if ($delete_route = $this->getRevisionDeleteRoute($entity_type)) {
52 $collection->add("entity.{$entity_type_id}.revision_delete", $delete_route);
54 {% if is_translatable %}
56 if ($translation_route = $this->getRevisionTranslationRevertRoute($entity_type)) {
57 $collection->add("{$entity_type_id}.revision_revert_translation_confirm", $translation_route);
62 if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) {
63 $collection->add("$entity_type_id.settings", $settings_form_route);
70 * Gets the collection route.
72 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
75 * @return \Symfony\Component\Routing\Route|null
76 * The generated route, if available.
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'));
84 '_entity_list' => $entity_type_id,
85 '_title' => "{$entity_type->getLabel()} list",
87 ->setRequirement('_permission', 'access {{ label|lower }} overview')
88 ->setOption('_admin_route', TRUE);
96 * Gets the version history route.
98 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
101 * @return \Symfony\Component\Routing\Route|null
102 * The generated route, if available.
104 protected function getHistoryRoute(EntityTypeInterface $entity_type) {
105 if ($entity_type->hasLinkTemplate('version-history')) {
106 $route = new Route($entity_type->getLinkTemplate('version-history'));
109 '_title' => "{$entity_type->getLabel()} revisions",
110 '_controller' => '\Drupal\{{ module }}\Controller\{{ entity_class }}Controller::revisionOverview',
112 ->setRequirement('_permission', 'access {{ label|lower }} revisions')
113 ->setOption('_admin_route', TRUE);
120 * Gets the revision route.
122 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
125 * @return \Symfony\Component\Routing\Route|null
126 * The generated route, if available.
128 protected function getRevisionRoute(EntityTypeInterface $entity_type) {
129 if ($entity_type->hasLinkTemplate('revision')) {
130 $route = new Route($entity_type->getLinkTemplate('revision'));
133 '_controller' => '\Drupal\{{ module }}\Controller\{{ entity_class }}Controller::revisionShow',
134 '_title_callback' => '\Drupal\{{ module }}\Controller\{{ entity_class }}Controller::revisionPageTitle',
136 ->setRequirement('_permission', 'access {{ label|lower }} revisions')
137 ->setOption('_admin_route', TRUE);
144 * Gets the revision revert route.
146 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
149 * @return \Symfony\Component\Routing\Route|null
150 * The generated route, if available.
152 protected function getRevisionRevertRoute(EntityTypeInterface $entity_type) {
153 if ($entity_type->hasLinkTemplate('revision_revert')) {
154 $route = new Route($entity_type->getLinkTemplate('revision_revert'));
157 '_form' => '\Drupal\{{ module }}\Form\{{ entity_class }}RevisionRevertForm',
158 '_title' => 'Revert to earlier revision',
160 ->setRequirement('_permission', 'revert all {{ label|lower }} revisions')
161 ->setOption('_admin_route', TRUE);
168 * Gets the revision delete route.
170 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
173 * @return \Symfony\Component\Routing\Route|null
174 * The generated route, if available.
176 protected function getRevisionDeleteRoute(EntityTypeInterface $entity_type) {
177 if ($entity_type->hasLinkTemplate('revision_delete')) {
178 $route = new Route($entity_type->getLinkTemplate('revision_delete'));
181 '_form' => '\Drupal\{{ module }}\Form\{{ entity_class }}RevisionDeleteForm',
182 '_title' => 'Delete earlier revision',
184 ->setRequirement('_permission', 'delete all {{ label|lower }} revisions')
185 ->setOption('_admin_route', TRUE);
190 {% if is_translatable %}
193 * Gets the revision translation revert route.
195 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
198 * @return \Symfony\Component\Routing\Route|null
199 * The generated route, if available.
201 protected function getRevisionTranslationRevertRoute(EntityTypeInterface $entity_type) {
202 if ($entity_type->hasLinkTemplate('translation_revert')) {
203 $route = new Route($entity_type->getLinkTemplate('translation_revert'));
206 '_form' => '\Drupal\{{ module }}\Form\{{ entity_class }}RevisionRevertTranslationForm',
207 '_title' => 'Revert to earlier revision of a translation',
209 ->setRequirement('_permission', 'revert all {{ label|lower }} revisions')
210 ->setOption('_admin_route', TRUE);
219 * Gets the settings form route.
221 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
224 * @return \Symfony\Component\Routing\Route|null
225 * The generated route, if available.
227 protected function getSettingsFormRoute(EntityTypeInterface $entity_type) {
228 if (!$entity_type->getBundleEntityType()) {
229 $route = new Route("/admin/structure/{$entity_type->id()}/settings");
232 '_form' => 'Drupal\{{ module }}\Form\{{ entity_class }}SettingsForm',
233 '_title' => "{$entity_type->getLabel()} settings",
235 ->setRequirement('_permission', $entity_type->getAdminPermission())
236 ->setOption('_admin_route', TRUE);