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

GraphQLConfigOverrides::getCacheableMetadata()   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 1
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
      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];
44
      }
45
    }
46
    return [];
47
  }
48
49
  /**
50
   * {@inheritdoc}
51
   */
52
  public function getCacheSuffix() {
53
    return 'graphql';
54
  }
55
56
  /**
57
   * {@inheritdoc}
58
   */
59
  public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
60
    return NULL;
61
  }
62
63
  /**
64
   * {@inheritdoc}
65
   */
66
  public function getCacheableMetadata($name) {
67
    return new CacheableMetadata();
68
  }
69
70
}
71