Completed
Pull Request — 8.x-3.x (#620)
by Sebastian
03:23
created

GraphQLConfigOverrides   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 67
rs 10
wmc 9
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B loadOverrides() 0 14 5
A getCacheSuffix() 0 3 1
A createConfigObject() 0 3 1
A getCacheableMetadata() 0 3 1
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