ViewResultType::applies()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 4
nc 3
nop 3
1
<?php
2
3
namespace Drupal\graphql_views\Plugin\GraphQL\Types;
4
5
use Drupal\graphql\GraphQL\Execution\ResolveContext;
6
use Drupal\graphql\Plugin\GraphQL\Types\TypePluginBase;
7
use GraphQL\Type\Definition\ResolveInfo;
8
9
/**
10
 * Expose views as root fields.
11
 *
12
 * @GraphQLType(
13
 *   id = "view_result_type",
14
 *   provider = "views",
15
 *   unions = {"ViewResult"},
16
 *   deriver = "Drupal\graphql_views\Plugin\Deriver\Types\ViewResultTypeDeriver"
17
 * )
18
 */
19
class ViewResultType extends TypePluginBase {
20
21
  /**
22
   * {@inheritdoc}
23
   */
24
  public function applies($object, ResolveContext $context, ResolveInfo $info) {
25
    if (isset($object['view'])) {
26
      /* @var \Drupal\views\Entity\View $view */
27
      $view = $object['view'];
28
      if ($this->pluginDefinition['view'] === $view->id() && $this->pluginDefinition['display'] == $view->current_display) {
29
        return TRUE;
30
      }
31
    }
32
33
    return parent::applies($object, $context, $info);
34
  }
35
36
}
37