Completed
Pull Request — 8.x-3.x (#550)
by Philipp
10:48
created

GraphQLConfigOverrides   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A loadOverrides() 0 11 3
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
9
/**
10
 * GraphQL config overrides.
11
 *
12
 * Enforce the GraphQL language negotiation always to be on top.
13
 */
14
class GraphQLConfigOverrides implements ConfigFactoryOverrideInterface {
15
16
  /**
17
   * The config storage service.
18
   *
19
   * @var \Drupal\Core\Config\StorageInterface
20
   */
21
  protected $baseStorage;
22
23
  /**
24
   * GraphQLConfigOverrides constructor.
25
   *
26
   * @param \Drupal\Core\Config\StorageInterface $storage
27
   *   The config storage service.
28
   */
29
  public function __construct(StorageInterface $storage) {
30
    $this->baseStorage = $storage;
31
  }
32
33
  /**
34
   * {@inheritdoc}
35
   */
36
  public function loadOverrides($names) {
37
    if (in_array('language.types', $names)) {
38
      $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];
44
    }
45
    return [];
46
  }
47
48
  /**
49
   * {@inheritdoc}
50
   */
51
  public function getCacheSuffix() {
52
    return 'graphql';
53
  }
54
55
  /**
56
   * {@inheritdoc}
57
   */
58
  public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
59
    return NULL;
60
  }
61
62
  /**
63
   * {@inheritdoc}
64
   */
65
  public function getCacheableMetadata($name) {
66
    return new CacheableMetadata();
67
  }
68
69
}
70