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);
42 * Gets the collection route.
44 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
47 * @return \Symfony\Component\Routing\Route|null
48 * The generated route, if available.
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'));
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(),
61 ->setRequirement('_permission', $entity_type->getAdminPermission())
62 ->setOption('_admin_route', TRUE);