3 namespace Drupal\fontyourface;
5 use Drupal\Core\Entity\EntityTypeInterface;
6 use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
7 use Symfony\Component\Routing\Route;
10 * Provides routes for Font entities.
12 * @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
13 * @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
15 class FontHtmlRouteProvider extends AdminHtmlRouteProvider {
20 public function getRoutes(EntityTypeInterface $entity_type) {
21 $collection = parent::getRoutes($entity_type);
23 $entity_type_id = $entity_type->id();
25 if ($collection_route = $this->getCollectionRoute($entity_type)) {
26 $collection->add("entity.{$entity_type_id}.collection", $collection_route);
29 if ($add_form_route = $this->getAddFormRoute($entity_type)) {
30 $collection->add("entity.{$entity_type_id}.add_form", $add_form_route);
33 if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) {
34 $collection->add("$entity_type_id.settings", $settings_form_route);
41 * Gets the collection route.
43 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
46 * @return \Symfony\Component\Routing\Route|null
47 * The generated route, if available.
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'));
55 '_entity_list' => $entity_type_id,
56 '_title' => "{$entity_type->getLabel()} list",
58 ->setRequirement('_permission', 'view font entities')
59 ->setOption('_admin_route', TRUE);
66 * Gets the add-form route.
68 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
71 * @return \Symfony\Component\Routing\Route|null
72 * The generated route, if available.
74 protected function getAddFormRoute(EntityTypeInterface $entity_type) {
75 if ($entity_type->hasLinkTemplate('add-form')) {
76 $entity_type_id = $entity_type->id();
78 $entity_type_id => ['type' => 'entity:' . $entity_type_id],
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')) {
89 '_entity_form' => "{$entity_type_id}.{$operation}",
90 '_title' => "Add {$entity_type->getLabel()}",
92 ->setRequirement('_entity_create_access', $entity_type_id);
95 ->setOption('parameters', $parameters)
96 ->setOption('_admin_route', TRUE);
103 * Gets the settings form route.
105 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
108 * @return \Symfony\Component\Routing\Route|null
109 * The generated route, if available.
111 protected function getSettingsFormRoute(EntityTypeInterface $entity_type) {
112 if (!$entity_type->getBundleEntityType()) {
113 $route = new Route("/admin/appearance/{$entity_type->id()}/settings");
116 '_form' => 'Drupal\fontyourface\Form\FontSettingsForm',
117 '_title' => "{$entity_type->getLabel()} settings",
119 ->setRequirement('_permission', $entity_type->getAdminPermission())
120 ->setOption('_admin_route', TRUE);