Completed
Push — 8.x-3.x ( 9f5f1b...885c5d )
by Sebastian
06:17 queued 04:05
created

ConfigurationRoutes::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 3
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 3
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql\Routing;
4
5
use Drupal\Core\Routing\RouteSubscriberBase;
6
use Drupal\graphql\Plugin\GraphQL\SchemaPluginManager;
7
use Symfony\Component\Routing\Route;
8
use Symfony\Component\Routing\RouteCollection;
9
10
/**
11
 * Registers routes for all configurable schemas.
12
 */
13 View Code Duplication
class ConfigurationRoutes extends RouteSubscriberBase {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
15
  /**
16
   * The graphql schema plugin manager.
17
   *
18
   * @var \Drupal\graphql\Plugin\GraphQL\SchemaPluginManager
19
   */
20
  protected $schemaManager;
21
22
  /**
23
   * Constructs a QueryRoutes object.
24
   *
25
   * @param \Drupal\graphql\Plugin\GraphQL\SchemaPluginManager $schemaManager
26
   *   The graphql schema plugin manager.
27
   */
28
  public function __construct(SchemaPluginManager $schemaManager) {
29
    $this->schemaManager = $schemaManager;
30
  }
31
32
  /**
33
   * Alters existing routes for a specific collection.
34
   *
35
   * @param \Symfony\Component\Routing\RouteCollection $collection
36
   *   The route collection for adding routes.
37
   */
38
  protected function alterRoutes(RouteCollection $collection) {
39
    $routes = new RouteCollection();
40
41
    foreach ($this->schemaManager->getDefinitions() as $key => $definition) {
42
      if (empty($definition['uses_plugins'])) {
43
        continue;
44
      }
45
46
      $routes->add("graphql.configuration.$key", new Route("{$definition['path']}/configure", [
47
        'schema' => $key,
48
        '_controller' => '\Drupal\graphql\Controller\ConfigurationController::configurationOverview',
49
        '_title' => 'Configuration',
50
      ], [
51
        '_admin_route' => 'TRUE',
52
      ]));
53
    }
54
55
    $collection->addCollection($routes);
56
  }
57
58
}
59