1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\graphql_views\Plugin\Deriver\Fields; |
4
|
|
|
|
5
|
|
|
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; |
6
|
|
|
use Drupal\graphql_views\Plugin\Deriver\ViewDeriverBase; |
7
|
|
|
use Drupal\views\Views; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Derive fields from configured views. |
11
|
|
|
*/ |
12
|
|
|
class ViewDeriver extends ViewDeriverBase implements ContainerDeriverInterface { |
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 (!$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, 'view']); |
32
|
|
|
$info = $this->getArgumentsInfo($display->getOption('arguments') ?: []); |
33
|
|
|
$arguments = []; |
34
|
|
|
$arguments += $this->getContextualArguments($info, $id); |
35
|
|
|
$arguments += $this->getPagerArguments($display); |
36
|
|
|
$arguments += $this->getSortArguments($display, $id); |
37
|
|
|
$arguments += $this->getFilterArguments($display, $id); |
38
|
|
|
$types = $this->getTypes($info); |
39
|
|
|
|
40
|
|
|
$this->derivatives[$id] = [ |
41
|
|
|
'id' => $id, |
42
|
|
|
'name' => $display->getGraphQLQueryName(), |
43
|
|
|
'type' => $display->getGraphQLResultName(), |
44
|
|
|
'parents' => $types, |
45
|
|
|
'arguments' => $arguments, |
46
|
|
|
'view' => $viewId, |
47
|
|
|
'display' => $displayId, |
48
|
|
|
'paged' => $this->isPaged($display), |
49
|
|
|
'arguments_info' => $info, |
50
|
|
|
] + $this->getCacheMetadataDefinition($view, $display) + $basePluginDefinition; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return parent::getDerivativeDefinitions($basePluginDefinition); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: