Completed
Pull Request — 8.x-3.x (#399)
by Sebastian
04:43 queued 02:12
created

ViewResultListDeriver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B getDerivativeDefinitions() 0 30 4
1
<?php
2
3
namespace Drupal\graphql_core\Plugin\Deriver\Fields;
4
5
use Drupal\graphql\Utility\StringHelper;
6
use Drupal\graphql_core\Plugin\Deriver\ViewDeriverBase;
7
use Drupal\views\Views;
8
9
/**
10
 * Derive fields from configured views.
11
 */
12
class ViewResultListDeriver extends ViewDeriverBase {
13
14
  /**
15
   * {@inheritdoc}
16
   */
17
  public function getDerivativeDefinitions($basePluginDefinition) {
18
    if ($this->entityTypeManager->hasDefinition('view')) {
19
      $viewStorage = $this->entityTypeManager->getStorage('view');
20
21
      foreach (Views::getApplicableViews('graphql_display') as list($viewId, $displayId)) {
22
        /** @var \Drupal\views\ViewEntityInterface $view */
23
        $view = $viewStorage->load($viewId);
24
        if (!$type = $this->getRowResolveType($view, $displayId)) {
25
          continue;
26
        }
27
28
        /** @var \Drupal\graphql\Plugin\views\display\GraphQL $display */
29
        $display = $this->getViewDisplay($view, $displayId);
30
31
        $id = implode('-', [$viewId, $displayId, 'result', 'list']);
32
        $style = $this->getViewStyle($view, $displayId);
33
        $this->derivatives[$id] = [
34
            'id' => $id,
35
            'type' => $type,
36
            'parents' => [$display->getGraphQLResultName()],
37
            'multi' => TRUE,
38
            'view' => $viewId,
39
            'display' => $displayId,
40
            'uses_fields' => $style->usesFields(),
41
          ] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
42
      }
43
    }
44
45
    return parent::getDerivativeDefinitions($basePluginDefinition);
46
  }
47
48
}
49