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();
35 if ($history_route = $this->getHistoryRoute($entity_type)) {
36 $collection->add("entity.{$entity_type_id}.version_history", $history_route);
39 if ($revision_route = $this->getRevisionRoute($entity_type)) {
40 $collection->add("entity.{$entity_type_id}.revision", $revision_route);
43 if ($revert_route = $this->getRevisionRevertRoute($entity_type)) {
44 $collection->add("entity.{$entity_type_id}.revision_revert", $revert_route);
47 if ($delete_route = $this->getRevisionDeleteRoute($entity_type)) {
48 $collection->add("entity.{$entity_type_id}.revision_delete", $delete_route);
50 {% if is_translatable %}
52 if ($translation_route = $this->getRevisionTranslationRevertRoute($entity_type)) {
53 $collection->add("{$entity_type_id}.revision_revert_translation_confirm", $translation_route);
58 if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) {
59 $collection->add("$entity_type_id.settings", $settings_form_route);
67 * Gets the version history route.
69 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
72 * @return \Symfony\Component\Routing\Route|null
73 * The generated route, if available.
75 protected function getHistoryRoute(EntityTypeInterface $entity_type) {
76 if ($entity_type->hasLinkTemplate('version-history')) {
77 $route = new Route($entity_type->getLinkTemplate('version-history'));
80 '_title' => "{$entity_type->getLabel()} revisions",
81 '_controller' => '\Drupal\{{ module }}\Controller\{{ entity_class }}Controller::revisionOverview',
83 ->setRequirement('_permission', 'access {{ label|lower }} revisions')
84 ->setOption('_admin_route', TRUE);
91 * Gets the revision route.
93 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
96 * @return \Symfony\Component\Routing\Route|null
97 * The generated route, if available.
99 protected function getRevisionRoute(EntityTypeInterface $entity_type) {
100 if ($entity_type->hasLinkTemplate('revision')) {
101 $route = new Route($entity_type->getLinkTemplate('revision'));
104 '_controller' => '\Drupal\{{ module }}\Controller\{{ entity_class }}Controller::revisionShow',
105 '_title_callback' => '\Drupal\{{ module }}\Controller\{{ entity_class }}Controller::revisionPageTitle',
107 ->setRequirement('_permission', 'access {{ label|lower }} revisions')
108 ->setOption('_admin_route', TRUE);
115 * Gets the revision revert route.
117 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
120 * @return \Symfony\Component\Routing\Route|null
121 * The generated route, if available.
123 protected function getRevisionRevertRoute(EntityTypeInterface $entity_type) {
124 if ($entity_type->hasLinkTemplate('revision_revert')) {
125 $route = new Route($entity_type->getLinkTemplate('revision_revert'));
128 '_form' => '\Drupal\{{ module }}\Form\{{ entity_class }}RevisionRevertForm',
129 '_title' => 'Revert to earlier revision',
131 ->setRequirement('_permission', 'revert all {{ label|lower }} revisions')
132 ->setOption('_admin_route', TRUE);
139 * Gets the revision delete route.
141 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
144 * @return \Symfony\Component\Routing\Route|null
145 * The generated route, if available.
147 protected function getRevisionDeleteRoute(EntityTypeInterface $entity_type) {
148 if ($entity_type->hasLinkTemplate('revision_delete')) {
149 $route = new Route($entity_type->getLinkTemplate('revision_delete'));
152 '_form' => '\Drupal\{{ module }}\Form\{{ entity_class }}RevisionDeleteForm',
153 '_title' => 'Delete earlier revision',
155 ->setRequirement('_permission', 'delete all {{ label|lower }} revisions')
156 ->setOption('_admin_route', TRUE);
161 {% if is_translatable %}
164 * Gets the revision translation revert route.
166 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
169 * @return \Symfony\Component\Routing\Route|null
170 * The generated route, if available.
172 protected function getRevisionTranslationRevertRoute(EntityTypeInterface $entity_type) {
173 if ($entity_type->hasLinkTemplate('translation_revert')) {
174 $route = new Route($entity_type->getLinkTemplate('translation_revert'));
177 '_form' => '\Drupal\{{ module }}\Form\{{ entity_class }}RevisionRevertTranslationForm',
178 '_title' => 'Revert to earlier revision of a translation',
180 ->setRequirement('_permission', 'revert all {{ label|lower }} revisions')
181 ->setOption('_admin_route', TRUE);
190 * Gets the settings form route.
192 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
195 * @return \Symfony\Component\Routing\Route|null
196 * The generated route, if available.
198 protected function getSettingsFormRoute(EntityTypeInterface $entity_type) {
199 if (!$entity_type->getBundleEntityType()) {
200 $route = new Route("/admin/structure/{$entity_type->id()}/settings");
203 '_form' => 'Drupal\{{ module }}\Form\{{ entity_class }}SettingsForm',
204 '_title' => "{$entity_type->getLabel()} settings",
206 ->setRequirement('_permission', $entity_type->getAdminPermission())
207 ->setOption('_admin_route', TRUE);