Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / fontyourface / src / FontHtmlRouteProvider.php
1 <?php
2
3 namespace Drupal\fontyourface;
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 Font entities.
11  *
12  * @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
13  * @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
14  */
15 class FontHtmlRouteProvider 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     if ($add_form_route = $this->getAddFormRoute($entity_type)) {
30       $collection->add("entity.{$entity_type_id}.add_form", $add_form_route);
31     }
32
33     if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) {
34       $collection->add("$entity_type_id.settings", $settings_form_route);
35     }
36
37     return $collection;
38   }
39
40   /**
41    * Gets the collection route.
42    *
43    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
44    *   The entity type.
45    *
46    * @return \Symfony\Component\Routing\Route|null
47    *   The generated route, if available.
48    */
49   protected function getCollectionRoute(EntityTypeInterface $entity_type) {
50     if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass()) {
51       $entity_type_id = $entity_type->id();
52       $route = new Route($entity_type->getLinkTemplate('collection'));
53       $route
54         ->setDefaults([
55           '_entity_list' => $entity_type_id,
56           '_title' => "{$entity_type->getLabel()} list",
57         ])
58         ->setRequirement('_permission', 'view font entities')
59         ->setOption('_admin_route', TRUE);
60
61       return $route;
62     }
63   }
64
65   /**
66    * Gets the add-form route.
67    *
68    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
69    *   The entity type.
70    *
71    * @return \Symfony\Component\Routing\Route|null
72    *   The generated route, if available.
73    */
74   protected function getAddFormRoute(EntityTypeInterface $entity_type) {
75     if ($entity_type->hasLinkTemplate('add-form')) {
76       $entity_type_id = $entity_type->id();
77       $parameters = [
78         $entity_type_id => ['type' => 'entity:' . $entity_type_id],
79       ];
80
81       $route = new Route($entity_type->getLinkTemplate('add-form'));
82       // Use the add form handler, if available, otherwise default.
83       $operation = 'default';
84       if ($entity_type->getFormClass('add')) {
85         $operation = 'add';
86       }
87       $route
88         ->setDefaults([
89           '_entity_form' => "{$entity_type_id}.{$operation}",
90           '_title' => "Add {$entity_type->getLabel()}",
91         ])
92         ->setRequirement('_entity_create_access', $entity_type_id);
93
94       $route
95         ->setOption('parameters', $parameters)
96         ->setOption('_admin_route', TRUE);
97
98       return $route;
99     }
100   }
101
102   /**
103    * Gets the settings form route.
104    *
105    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
106    *   The entity type.
107    *
108    * @return \Symfony\Component\Routing\Route|null
109    *   The generated route, if available.
110    */
111   protected function getSettingsFormRoute(EntityTypeInterface $entity_type) {
112     if (!$entity_type->getBundleEntityType()) {
113       $route = new Route("/admin/appearance/{$entity_type->id()}/settings");
114       $route
115         ->setDefaults([
116           '_form' => 'Drupal\fontyourface\Form\FontSettingsForm',
117           '_title' => "{$entity_type->getLabel()} settings",
118         ])
119         ->setRequirement('_permission', $entity_type->getAdminPermission())
120         ->setOption('_admin_route', TRUE);
121
122       return $route;
123     }
124   }
125
126 }