1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\graphql\Config; |
4
|
|
|
|
5
|
|
|
use Drupal\Core\Cache\CacheableMetadata; |
6
|
|
|
use Drupal\Core\Config\ConfigFactoryOverrideInterface; |
7
|
|
|
use Drupal\Core\Config\StorageInterface; |
8
|
|
|
use Drupal\language\LanguageNegotiationMethodManager; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* GraphQL config overrides. |
12
|
|
|
* |
13
|
|
|
* Enforce the GraphQL language negotiation always to be on top. |
14
|
|
|
*/ |
15
|
|
|
class GraphQLConfigOverrides implements ConfigFactoryOverrideInterface { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The config storage service. |
19
|
|
|
* |
20
|
|
|
* @var \Drupal\Core\Config\StorageInterface |
21
|
|
|
*/ |
22
|
|
|
protected $baseStorage; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The negotiator manager service. |
26
|
|
|
* |
27
|
|
|
* @var \Drupal\language\LanguageNegotiationMethodManager |
28
|
|
|
*/ |
29
|
|
|
protected $negotiatorManager; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* GraphQLConfigOverrides constructor. |
33
|
|
|
* |
34
|
|
|
* @param \Drupal\Core\Config\StorageInterface $storage |
35
|
|
|
* The config storage service. |
36
|
|
|
*/ |
37
|
|
|
public function __construct(StorageInterface $storage, LanguageNegotiationMethodManager $negotiatorManager) { |
38
|
|
|
$this->baseStorage = $storage; |
39
|
|
|
$this->negotiatorManager = $negotiatorManager; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
|
|
public function loadOverrides($names) { |
46
|
|
|
if ( |
47
|
|
|
in_array('language.types', $names) |
48
|
|
|
&& $this->negotiatorManager->hasDefinition('language-graphql') |
49
|
|
|
&& $config = $this->baseStorage->read('language.types') |
50
|
|
|
) { |
51
|
|
|
foreach (array_keys($config['negotiation']) as $type) { |
52
|
|
|
$config['negotiation'][$type]['enabled']['language-graphql'] = -999; |
53
|
|
|
asort($config['negotiation'][$type]['enabled']); |
54
|
|
|
} |
55
|
|
|
return ['language.types' => $config]; |
56
|
|
|
} |
57
|
|
|
return []; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
|
public function getCacheSuffix() { |
64
|
|
|
return 'graphql'; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) { |
71
|
|
|
return NULL; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
|
|
public function getCacheableMetadata($name) { |
78
|
|
|
return new CacheableMetadata(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|