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

ViewResultListDeriver::getDerivativeDefinitions()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 30
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

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