Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / fontyourface / modules / local_fonts / src / LocalFontConfigEntityHtmlRouteProvider.php
1 <?php
2
3 namespace Drupal\local_fonts;
4
5 use Drupal\Core\Entity\EntityTypeInterface;
6 use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
7 use Symfony\Component\Routing\Route;
8
9 /**
10  * Provides routes for Custom Font entities.
11  *
12  * @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
13  * @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
14  */
15 class LocalFontConfigEntityHtmlRouteProvider extends AdminHtmlRouteProvider {
16
17   /**
18    * {@inheritdoc}
19    */
20   public function getRoutes(EntityTypeInterface $entity_type) {
21     $collection = parent::getRoutes($entity_type);
22
23     $entity_type_id = $entity_type->id();
24
25     if ($collection_route = $this->getCollectionRoute($entity_type)) {
26       $collection->add("entity.{$entity_type_id}.collection", $collection_route);
27     }
28
29     return $collection;
30   }
31
32   /**
33    * Gets the collection route.
34    *
35    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
36    *   The entity type.
37    *
38    * @return \Symfony\Component\Routing\Route|null
39    *   The generated route, if available.
40    */
41   protected function getCollectionRoute(EntityTypeInterface $entity_type) {
42     if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass()) {
43       $entity_type_id = $entity_type->id();
44       $route = new Route($entity_type->getLinkTemplate('collection'));
45       $route
46         ->setDefaults([
47           '_entity_list' => $entity_type_id,
48           // Make sure this is not a TranslatableMarkup object as the
49           // TitleResolver translates this string again.
50           '_title' => (string) $entity_type->getLabel(),
51         ])
52         ->setRequirement('_permission', $entity_type->getAdminPermission())
53         ->setOption('_admin_route', TRUE);
54
55       return $route;
56     }
57   }
58
59 }