Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / templates / module / src / entity-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
38     return $collection;
39   }
40
41   /**
42    * Gets the collection route.
43    *
44    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
45    *   The entity type.
46    *
47    * @return \Symfony\Component\Routing\Route|null
48    *   The generated route, if available.
49    */
50   protected function getCollectionRoute(EntityTypeInterface $entity_type) {
51     if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass()) {
52       $entity_type_id = $entity_type->id();
53       $route = new Route($entity_type->getLinkTemplate('collection'));
54       $route
55         ->setDefaults([
56           '_entity_list' => $entity_type_id,
57           // Make sure this is not a TranslatableMarkup object as the
58           // TitleResolver translates this string again.
59           '_title' => (string) $entity_type->getLabel(),
60         ])
61         ->setRequirement('_permission', $entity_type->getAdminPermission())
62         ->setOption('_admin_route', TRUE);
63
64       return $route;
65     }
66   }
67 {% endblock %}