Passed
Pull Request — 8.x-1.x (#40)
by
unknown
07:19
created

GraphQLEntityRow::render()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 3
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Drupal\graphql_views\Plugin\views\row;
4
5
use Drupal\Core\Entity\EntityInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Entity\EntityInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Drupal\Core\Entity\EntityRepositoryInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Entity\EntityRepositoryInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Drupal\Core\Entity\EntityTypeManagerInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Entity\EntityTypeManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Drupal\Core\Entity\Plugin\DataType\EntityAdapter;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Entity\Plugin\DataType\EntityAdapter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Drupal\Core\Language\LanguageManagerInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Language\LanguageManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Drupal\views\Entity\Render\EntityTranslationRenderTrait;
0 ignored issues
show
Bug introduced by
The type Drupal\views\Entity\Rend...yTranslationRenderTrait was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Drupal\views\Plugin\views\row\RowPluginBase;
0 ignored issues
show
Bug introduced by
The type Drupal\views\Plugin\views\row\RowPluginBase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Drupal\views\ResultRow;
0 ignored issues
show
Bug introduced by
The type Drupal\views\ResultRow was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Symfony\Component\DependencyInjection\ContainerInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...tion\ContainerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
15
/**
16
 * Plugin which displays entities as raw data.
17
 *
18
 * @ViewsRow(
19
 *   id = "graphql_entity",
20
 *   title = @Translation("Entity"),
21
 *   help = @Translation("Use entities as row data."),
22
 *   display_types = {"graphql"}
23
 * )
24
 */
25
class GraphQLEntityRow extends RowPluginBase {
26
27
  use EntityTranslationRenderTrait {
28
    getEntityTranslationRenderer as getEntityTranslationRendererBase;
29
  }
30
31
  /**
32
   * {@inheritdoc}
33
   */
34
  protected $usesOptions = FALSE;
35
36
  /**
37
   * The language manager.
38
   *
39
   * @var \Drupal\Core\Language\LanguageManagerInterface
40
   */
41
  protected $languageManager;
42
43
  /**
44
   * The entity type manager.
45
   *
46
   * @var \Drupal\Core\Entity\EntityTypeManager
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Entity\EntityTypeManager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
47
   */
48
  protected $entityTypeManager;
49
50
  /**
51
   * The entity type bundle info.
52
   *
53
   * @var \Drupal\Core\Entity\EntityRepository
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Entity\EntityRepository was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
54
   */
55
  protected $entityRepository;
56
57
  /**
58
   * {@inheritdoc}
59
   */
60
  public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) {
61
    $plugin = parent::create($container, $configuration, $pluginId, $pluginDefinition);
62
    $plugin->setLanguageManager($container->get('language_manager'));
63
    $plugin->setEntityTypeManager($container->get('entity_type.manager'));
64
    $plugin->setEntityRepository($container->get('entity.repository'));
65
    return $plugin;
66
  }
67
68
  /**
69
   * Set the language manager.
70
   *
71
   * @param \Drupal\Core\Language\LanguageManagerInterface $languageManager
72
   *   The language manager.
73
   */
74
  protected function setLanguageManager(LanguageManagerInterface $languageManager) {
75
    $this->languageManager = $languageManager;
76
  }
77
78
  /**
79
   * Set the entity type manager.
80
   *
81
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
82
   *   The entity type manager.
83
   */
84
  protected function setEntityTypeManager(EntityTypeManagerInterface $entityTypeManager) {
85
    $this->entityTypeManager = $entityTypeManager;
86
  }
87
88
  /**
89
   * Set the entity repository.
90
   *
91
   * @param \Drupal\Core\Entity\EntityRepositoryInterface $entityRepository
92
   *   The entity repository.
93
   */
94
  protected function setEntityRepository(EntityRepositoryInterface $entityRepository) {
95
    $this->entityRepository = $entityRepository;
96
  }
97
98
  /**
99
   * {@inheritdoc}
100
   */
101
  public function render($row) {
102
    if ($entity = $this->getEntityFromRow($row)) {
103
      return $this->view->getBaseEntityType() ? $this->getEntityTranslation($entity, $row) : $entity;
104
    }
105
106
    return NULL;
107
  }
108
109
  /**
110
   * {@inheritdoc}
111
   */
112
  protected function getEntityTranslationRenderer() {
113
    if ($this->view->getBaseEntityType()) {
114
      return $this->getEntityTranslationRendererBase();
115
    }
116
117
    return NULL;
118
  }
119
120
  /**
121
   * {@inheritdoc}
122
   */
123
  public function getEntityTypeId() {
124
    if ($entityType = $this->view->getBaseEntityType()) {
125
      return $entityType->id();
126
    }
127
128
    return NULL;
129
  }
130
131
  /**
132
   * {@inheritdoc}
133
   */
134
  protected function getLanguageManager() {
135
    return $this->languageManager;
136
  }
137
138
  /**
139
   * {@inheritdoc}
140
   */
141
  protected function getEntityTypeManager() {
142
    return $this->entityTypeManager;
143
  }
144
145
  /**
146
   * {@inheritdoc}
147
   */
148
  protected function getEntityRepository() {
149
    return $this->entityRepository;
150
  }
151
152
  /**
153
   * Retrieves the entity object from a result row.
154
   *
155
   * @param \Drupal\Views\ResultRow $row
0 ignored issues
show
Bug introduced by
The type Drupal\Views\ResultRow was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
156
   *   The views result row object.
157
   *
158
   * @return null|\Drupal\Core\Entity\EntityInterface
159
   *   The extracted entity object or NULL if it could not be retrieved.
160
   */
161
  protected function getEntityFromRow(ResultRow $row) {
162
    if (isset($row->_entity) && $row->_entity instanceof EntityInterface) {
163
      return $row->_entity;
164
    }
165
166
    if (isset($row->_object) && $row->_object instanceof EntityAdapter) {
167
      return $row->_object->getValue();
168
    }
169
170
    return NULL;
171
  }
172
173
  /**
174
   * {@inheritdoc}
175
   */
176
  protected function getView() {
177
    return $this->view;
178
  }
179
180
  /**
181
   * {@inheritdoc}
182
   */
183
  public function query() {
184
    parent::query();
185
186
    if ($this->view->getBaseEntityType()) {
187
      $this->getEntityTranslationRenderer()->query($this->view->getQuery());
188
    }
189
  }
190
191
}
192