Completed
Pull Request — 8.x-3.x (#448)
by Sebastian
01:59
created

EntityQueryMapQueryProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getQuery() 0 13 4
1
<?php
2
3
namespace Drupal\graphql\QueryProvider;
4
5
use Drupal\Core\Entity\EntityTypeManagerInterface;
6
7
class EntityQueryMapQueryProvider implements QueryProviderInterface {
8
  /**
9
   * The entity type manager service.
10
   *
11
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
12
   */
13
  protected $entityTypeManager;
14
15
  /**
16
   * Constructs a QueryProvider object.
17
   *
18
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
19
   *   The entity type manager service.
20
   */
21
  public function __construct(EntityTypeManagerInterface $entityTypeManager) {
22
    $this->entityTypeManager = $entityTypeManager;
23
  }
24
25
  /**
26
   * {@inheritdoc}
27
   */
28
  public function getQuery(array $params) {
29
    if (empty($params['version']) || empty($params['id'])) {
30
      return NULL;
31
    }
32
33
    $storage = $this->entityTypeManager->getStorage('graphql_query_map');
34
    /** @var \Drupal\graphql\Entity\QueryMapInterface $map */
35
    if ($map = $storage->load($params['version'])) {
36
      return $map->getQuery($params['id']);
37
    }
38
39
    return NULL;
40
  }
41
}
42