ViewResultListDeriver::getDerivativeDefinitions()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 9.456
c 0
b 0
f 0
cc 4
nc 2
nop 1
1
<?php
2
3
namespace Drupal\graphql_views\Plugin\Deriver\Fields;
4
5
use Drupal\graphql\Utility\StringHelper;
6
use Drupal\graphql_views\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_views\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' => StringHelper::listType($type),
36
          'parents' => [$display->getGraphQLResultName()],
37
          'view' => $viewId,
38
          'display' => $displayId,
39
          'uses_fields' => $style->usesFields(),
40
        ] + $this->getCacheMetadataDefinition($view, $display) + $basePluginDefinition;
41
      }
42
    }
43
44
    return parent::getDerivativeDefinitions($basePluginDefinition);
45
  }
46
47
}
48