Passed
Pull Request — 8.x-2.x (#26)
by Frédéric G.
02:49
created

getSettingsFormRoute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\mongodb_watchdog;
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 Event template entities.
11
 *
12
 * @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
13
 * @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
14
 */
15
class EventTemplateHtmlRouteProvider extends AdminHtmlRouteProvider {
16
17
  /**
18
   * {@inheritdoc}
19
   */
20
  public function getRoutes(EntityTypeInterface $entity_type) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
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 ($settings_form_route = $this->getSettingsFormRoute($entity_type)) {
30
      $collection->add("$entity_type_id.settings", $settings_form_route);
31
    }
32
33
    return $collection;
34
  }
35
36
  /**
37
   * Gets the collection route.
38
   *
39
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
40
   *   The entity type.
41
   *
42
   * @return \Symfony\Component\Routing\Route|null
43
   *   The generated route, if available.
44
   */
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'));
49
      $route
50
        ->setDefaults([
51
          '_entity_list' => $entity_type_id,
52
          '_title' => "{$entity_type->getLabel()} list",
53
        ])
54
        ->setRequirement('_permission', 'access event template overview')
55
        ->setOption('_admin_route', TRUE);
56
57
      return $route;
58
    }
59
  }
60
61
  /**
62
   * Gets the settings form route.
63
   *
64
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
65
   *   The entity type.
66
   *
67
   * @return \Symfony\Component\Routing\Route|null
68
   *   The generated route, if available.
69
   */
70
  protected function getSettingsFormRoute(EntityTypeInterface $entity_type) {
71
    if (!$entity_type->getBundleEntityType()) {
72
      $route = new Route("/admin/structure/{$entity_type->id()}/settings");
73
      $route
74
        ->setDefaults([
75
          '_form' => 'Drupal\mongodb_watchdog\Form\EventTemplateSettingsForm',
76
          '_title' => "{$entity_type->getLabel()} settings",
77
        ])
78
        ->setRequirement('_permission', $entity_type->getAdminPermission())
79
        ->setOption('_admin_route', TRUE);
80
81
      return $route;
82
    }
83
  }
84
85
}
86