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 display entities.
12 * @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
13 * @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
15 class FontDisplayHtmlRouteProvider 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);
37 * Gets the collection route.
39 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
42 * @return \Symfony\Component\Routing\Route|null
43 * The generated route, if available.
45 protected function getCollectionRoute(EntityTypeInterface $entity_type) {
46 if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass()) {
47 $entity_type_id = $entity_type->id();
48 $route = new Route($entity_type->getLinkTemplate('collection'));
51 '_entity_list' => $entity_type_id,
52 // Make sure this is not a TranslatableMarkup object as the
53 // TitleResolver translates this string again.
54 '_title' => (string) $entity_type->getLabel(),
56 ->setRequirement('_permission', $entity_type->getAdminPermission())
57 ->setOption('_admin_route', TRUE);
64 * Gets the add-form route.
66 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
69 * @return \Symfony\Component\Routing\Route|null
70 * The generated route, if available.
72 protected function getAddFormRoute(EntityTypeInterface $entity_type) {
73 if ($entity_type->hasLinkTemplate('add-form')) {
74 $entity_type_id = $entity_type->id();
75 $route = new Route($entity_type->getLinkTemplate('add-form'));
76 // Use the add form handler, if available, otherwise default.
77 $operation = 'default';
78 if ($entity_type->getFormClass('add')) {
83 '_entity_form' => "{$entity_type_id}.{$operation}",
84 '_title' => "Add {$entity_type->getLabel()}",
86 ->setRequirement('_entity_create_access', $entity_type_id)
87 ->setOption('parameters', [
88 $entity_type_id => ['type' => 'entity:' . $entity_type_id],
90 ->setOption('_admin_route', TRUE);