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

GraphQLConfigOverrides::createConfigObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
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