|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\graphql\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Core\DependencyInjection\ContainerInjectionInterface; |
|
|
|
|
|
|
6
|
|
|
use Drupal\Core\Extension\ModuleHandlerInterface; |
|
|
|
|
|
|
7
|
|
|
use Drupal\Core\StringTranslation\StringTranslationTrait; |
|
|
|
|
|
|
8
|
|
|
use Drupal\graphql\Plugin\SchemaPluginManager; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class SchemaOverviewController implements ContainerInjectionInterface { |
|
12
|
|
|
|
|
13
|
|
|
use StringTranslationTrait; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* The schema plugin manager service. |
|
17
|
|
|
* |
|
18
|
|
|
* @var \Drupal\graphql\Plugin\SchemaPluginManager |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $schemaManager; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* The module handler service. |
|
24
|
|
|
* |
|
25
|
|
|
* @var \Drupal\Core\Extension\ModuleHandlerInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $moduleHandler; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
|
|
public static function create(ContainerInterface $container) { |
|
33
|
|
|
return new static( |
|
34
|
|
|
$container->get('module_handler'), |
|
35
|
|
|
$container->get('plugin.manager.graphql.schema') |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* SchemaOverviewController constructor. |
|
41
|
|
|
* |
|
42
|
|
|
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler |
|
43
|
|
|
* The module handler srevice. |
|
44
|
|
|
* @param \Drupal\graphql\Plugin\SchemaPluginManager $schemaManager |
|
45
|
|
|
* The schema plugin manager service. |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct(ModuleHandlerInterface $moduleHandler, SchemaPluginManager $schemaManager) { |
|
48
|
|
|
$this->schemaManager = $schemaManager; |
|
49
|
|
|
$this->moduleHandler = $moduleHandler; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Renders a table of available schemas. |
|
54
|
|
|
* |
|
55
|
|
|
* @return array |
|
56
|
|
|
* The renderable array for the overview table. |
|
57
|
|
|
*/ |
|
58
|
|
|
public function listSchemas() { |
|
59
|
|
|
$table = [ |
|
60
|
|
|
'#type' => 'table', |
|
61
|
|
|
'#header' => [ |
|
62
|
|
|
$this->t('Schema'), |
|
63
|
|
|
$this->t('Provider'), |
|
64
|
|
|
$this->t('Operations'), |
|
65
|
|
|
], |
|
66
|
|
|
'#attributes' => [ |
|
67
|
|
|
'id' => 'graphql-schemas', |
|
68
|
|
|
], |
|
69
|
|
|
]; |
|
70
|
|
|
|
|
71
|
|
|
foreach ($this->schemaManager->getDefinitions() as $key => $definition) { |
|
72
|
|
|
$table["schema:$key"]['name'] = [ |
|
73
|
|
|
'#plain_text' => $definition['name'], |
|
74
|
|
|
]; |
|
75
|
|
|
|
|
76
|
|
|
$table["schema:$key"]['provider'] = [ |
|
77
|
|
|
'#plain_text' => $this->moduleHandler->getName($definition['provider']), |
|
78
|
|
|
]; |
|
79
|
|
|
|
|
80
|
|
|
$table["schema:$key"]['operations'] = $this->buildOperations($key, $definition); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return $table; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Builds a renderable list of operation links for a schema. |
|
88
|
|
|
* |
|
89
|
|
|
* @param string $pluginId |
|
90
|
|
|
* The plugin id. |
|
91
|
|
|
* @param array $pluginDefinition |
|
92
|
|
|
* The plugin definition array. |
|
93
|
|
|
* |
|
94
|
|
|
* @return array |
|
95
|
|
|
* A renderable array of operation links. |
|
96
|
|
|
*/ |
|
97
|
|
|
protected function buildOperations($pluginId, array $pluginDefinition) { |
|
98
|
|
|
$build = [ |
|
99
|
|
|
'#type' => 'operations', |
|
100
|
|
|
'#links' => $this->getOperations($pluginId, $pluginDefinition), |
|
101
|
|
|
]; |
|
102
|
|
|
|
|
103
|
|
|
return $build; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Provides an array of information to build a list of operation links. |
|
108
|
|
|
* |
|
109
|
|
|
* @param $pluginId |
|
110
|
|
|
* The plugin id. |
|
111
|
|
|
* @param $pluginDefinition |
|
112
|
|
|
* The plugin definition array. |
|
113
|
|
|
* |
|
114
|
|
|
* @return array |
|
115
|
|
|
* An associative array of operation link data for this list, keyed by |
|
116
|
|
|
* operation name, containing the following key-value pairs: |
|
117
|
|
|
* - title: The localized title of the operation. |
|
118
|
|
|
* - url: An instance of \Drupal\Core\Url for the operation URL. |
|
119
|
|
|
* - weight: The weight of this operation. |
|
120
|
|
|
*/ |
|
121
|
|
|
protected function getOperations($pluginId, $pluginDefinition) { |
|
122
|
|
|
$operations = $this->moduleHandler->invokeAll('graphql_schema_operations', [$pluginId, $pluginDefinition]); |
|
123
|
|
|
$this->moduleHandler->alter('graphql_schema_operations', $operations, $pluginId, $pluginDefinition); |
|
124
|
|
|
uasort($operations, '\Drupal\Component\Utility\SortArray::sortByWeightElement'); |
|
125
|
|
|
|
|
126
|
|
|
return $operations; |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths