GraphQL::render()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Drupal\graphql_views\Plugin\views\style;
4
5
use Drupal\views\Plugin\views\style\StylePluginBase;
6
7
/**
8
 * Provides a style plugin for GraphQL views.
9
 *
10
 * @ViewsStyle(
11
 *   id = "graphql",
12
 *   title = @Translation("GraphQL"),
13
 *   help = @Translation("Provides entity or field rows to GraphQL."),
14
 *   display_types = {"graphql"}
15
 * )
16
 */
17
class GraphQL extends StylePluginBase {
18
19
  /**
20
   * {@inheritdoc}
21
   */
22
  protected $usesRowPlugin = TRUE;
23
24
  /**
25
   * {@inheritdoc}
26
   */
27
  protected $usesFields = FALSE;
28
29
  /**
30
   * {@inheritdoc}
31
   */
32
  protected $usesGrouping = FALSE;
33
34
  /**
35
   * {@inheritdoc}
36
   */
37
  public function render() {
38
    $rows = [];
39
    // If the Data Entity row plugin is used, this will be an array of entities
40
    // which will pass through Serializer to one of the registered Normalizers,
41
    // which will transform it to arrays/scalars. If the Data field row plugin
42
    // is used, $rows will not contain objects and will pass directly to the
43
    // Encoder.
44
    foreach ($this->view->result as $row_index => $row) {
45
      $this->view->row_index = $row_index;
46
      $rows[] = $this->view->rowPlugin->render($row);
47
    }
48
    unset($this->view->row_index);
49
50
    return $rows;
51
  }
52
}
53