Completed
Pull Request — 8.x-3.x (#525)
by Philipp
05:17
created

EntityQueryMapQueryProvider::__construct()   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
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Drupal\graphql\GraphQL\QueryProvider;
4
5
use Drupal\Core\Entity\EntityTypeManagerInterface;
6
use GraphQL\Server\OperationParams;
7
8
class EntityQueryMapQueryProvider implements QueryProviderInterface {
9
10
  /**
11
   * The entity type manager service.
12
   *
13
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
14
   */
15
  protected $entityTypeManager;
16
17
  /**
18
   * QueryProvider constructor.
19
   *
20
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
21
   *   The entity type manager service.
22
   */
23
  public function __construct(EntityTypeManagerInterface $entityTypeManager) {
24
    $this->entityTypeManager = $entityTypeManager;
25
  }
26
27
  /**
28
   * {@inheritdoc}
29
   */
30
  public function getQuery($id, OperationParams $operation) {
31
    list($version, $id) = explode(':', $id);
32
33
    // Check that the id is properly formatted.
34
    if (empty($version) || empty($id)) {
35
      return NULL;
36
    }
37
38
    $storage = $this->entityTypeManager->getStorage('graphql_query_map');
39
    /** @var \Drupal\graphql\Entity\QueryMapInterface $map */
40
    if ($map = $storage->load($version)) {
41
      return $map->getQuery($id);
42
    }
43
44
    return NULL;
45
  }
46
}
47