1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\graphql_views\Plugin\views\row; |
4
|
|
|
|
5
|
|
|
use Drupal\Core\Entity\EntityInterface; |
|
|
|
|
6
|
|
|
use Drupal\Core\Entity\EntityRepositoryInterface; |
|
|
|
|
7
|
|
|
use Drupal\Core\Entity\EntityTypeManagerInterface; |
|
|
|
|
8
|
|
|
use Drupal\Core\Entity\Plugin\DataType\EntityAdapter; |
|
|
|
|
9
|
|
|
use Drupal\Core\Language\LanguageManagerInterface; |
|
|
|
|
10
|
|
|
use Drupal\views\Entity\Render\EntityTranslationRenderTrait; |
|
|
|
|
11
|
|
|
use Drupal\views\Plugin\views\row\RowPluginBase; |
|
|
|
|
12
|
|
|
use Drupal\views\ResultRow; |
|
|
|
|
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
|
|
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 |
|
|
|
|
47
|
|
|
*/ |
48
|
|
|
protected $entityTypeManager; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* The entity type bundle info. |
52
|
|
|
* |
53
|
|
|
* @var \Drupal\Core\Entity\EntityRepository |
|
|
|
|
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 |
|
|
|
|
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
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths