1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\graphql\GraphQL; |
4
|
|
|
|
5
|
|
|
use Drupal\Component\Plugin\ConfigurablePluginInterface; |
6
|
|
|
use Drupal\graphql\Plugin\GraphQL\TypeSystemPluginInterface; |
7
|
|
|
|
8
|
|
|
trait PluginReferenceTrait { |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* The associated type system plugin. |
12
|
|
|
* |
13
|
|
|
* @var \Drupal\graphql\Plugin\GraphQL\TypeSystemPluginInterface |
14
|
|
|
*/ |
15
|
|
|
protected $plugin; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The schema builder object. |
19
|
|
|
* |
20
|
|
|
* @var \Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilderInterface |
21
|
|
|
*/ |
22
|
|
|
protected $builder; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
public function getPlugin() { |
28
|
|
|
if (is_array($this->plugin)) { |
29
|
|
|
$this->plugin = $this->builder->getInstance( |
30
|
|
|
$this->plugin['type'], |
31
|
|
|
$this->plugin['id'], |
32
|
|
|
$this->plugin['configuration'] |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return $this->plugin; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
public function getPluginDefinition() { |
43
|
|
|
if (is_array($this->plugin)) { |
44
|
|
|
return $this->plugin['definition']; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $this->getPlugin()->getPluginDefinition(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
public function getPluginId() { |
54
|
|
|
if (is_array($this->plugin)) { |
55
|
|
|
return $this->plugin['id']; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return $this->getPlugin()->getPluginId(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public function __sleep() { |
65
|
|
|
// Instead of serializing the referenced plugin, we just serialize the |
66
|
|
|
// plugin id and configuration. |
67
|
|
|
if ($this->plugin instanceof TypeSystemPluginInterface) { |
68
|
|
|
$this->plugin = [ |
|
|
|
|
69
|
|
|
'id' => $this->plugin->getPluginId(), |
70
|
|
|
'type' => $this->plugin->getPluginDefinition()['pluginType'], |
71
|
|
|
'configuration' => $this->plugin instanceof ConfigurablePluginInterface ? $this->plugin->getConfiguration() : [], |
|
|
|
|
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return array_keys(get_object_vars($this)); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..