Skip to content

Commit 8445d04

Browse files
FireGhostfubhy
authored andcommitted
1 parent 2ac450c commit 8445d04

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

graphql.install

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,18 @@ function graphql_requirements($phase) {
1919
],
2020
];
2121
}
22+
23+
/**
24+
* Implements hook_uninstall().
25+
*/
26+
function graphql_uninstall() {
27+
// Remove the config keys set in GraphQLConfigOverrides::loadOverrides().
28+
/** @var \Drupal\Core\Config\ConfigFactoryInterface $configFactory */
29+
$configFactory = \Drupal::getContainer()->get('config.factory');
30+
$languageTypes = $configFactory->getEditable('language.types');
31+
$negotiation = $languageTypes->get('negotiation');
32+
foreach (array_keys($negotiation) as $type) {
33+
unset($negotiation[$type]['enabled']['language-graphql']);
34+
}
35+
$languageTypes->set('negotiation', $negotiation)->save();
36+
}

graphql.services.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ services:
267267

268268
graphql.config_factory_override:
269269
class: Drupal\graphql\Config\GraphQLConfigOverrides
270-
arguments: ['@config.storage']
270+
arguments: ['@config.storage', '@plugin.manager.language_negotiation_method']
271271
tags:
272272
- { name: config.factory.override, priority: -253 }
273-

src/Config/GraphQLConfigOverrides.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Drupal\Core\Cache\CacheableMetadata;
66
use Drupal\Core\Config\ConfigFactoryOverrideInterface;
77
use Drupal\Core\Config\StorageInterface;
8+
use Drupal\language\LanguageNegotiationMethodManager;
89

910
/**
1011
* GraphQL config overrides.
@@ -20,28 +21,38 @@ class GraphQLConfigOverrides implements ConfigFactoryOverrideInterface {
2021
*/
2122
protected $baseStorage;
2223

24+
/**
25+
* The negotiator manager service.
26+
*
27+
* @var \Drupal\language\LanguageNegotiationMethodManager
28+
*/
29+
protected $negotiatorManager;
30+
2331
/**
2432
* GraphQLConfigOverrides constructor.
2533
*
2634
* @param \Drupal\Core\Config\StorageInterface $storage
2735
* The config storage service.
2836
*/
29-
public function __construct(StorageInterface $storage) {
37+
public function __construct(StorageInterface $storage, LanguageNegotiationMethodManager $negotiatorManager) {
3038
$this->baseStorage = $storage;
39+
$this->negotiatorManager = $negotiatorManager;
3140
}
3241

3342
/**
3443
* {@inheritdoc}
3544
*/
3645
public function loadOverrides($names) {
37-
if (in_array('language.types', $names)) {
38-
if ($config = $this->baseStorage->read('language.types')) {
39-
foreach (array_keys($config['negotiation']) as $type) {
40-
$config['negotiation'][$type]['enabled']['language-graphql'] = -999;
41-
asort($config['negotiation'][$type]['enabled']);
42-
}
43-
return ['language.types' => $config];
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']);
4454
}
55+
return ['language.types' => $config];
4556
}
4657
return [];
4758
}

0 commit comments

Comments
 (0)