|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\graphql_core\Plugin\GraphQL\Fields\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Core\DependencyInjection\DependencySerializationTrait; |
|
|
|
|
|
|
6
|
|
|
use Drupal\Core\Entity\ContentEntityInterface; |
|
|
|
|
|
|
7
|
|
|
use Drupal\Core\Entity\EntityTypeManagerInterface; |
|
|
|
|
|
|
8
|
|
|
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; |
|
|
|
|
|
|
9
|
|
|
use Drupal\Core\Render\RenderContext; |
|
|
|
|
|
|
10
|
|
|
use Drupal\Core\Render\RendererInterface; |
|
|
|
|
|
|
11
|
|
|
use Drupal\graphql\GraphQL\Cache\CacheableValue; |
|
12
|
|
|
use Drupal\graphql\GraphQL\Execution\ResolveContext; |
|
13
|
|
|
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
|
|
|
|
15
|
|
|
use GraphQL\Type\Definition\ResolveInfo; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @GraphQLField( |
|
19
|
|
|
* id = "entity_rendered", |
|
20
|
|
|
* name = "entityRendered", |
|
21
|
|
|
* type = "String", |
|
22
|
|
|
* secure = true, |
|
23
|
|
|
* deriver = "Drupal\graphql_core\Plugin\Deriver\Fields\EntityRenderedDeriver", |
|
24
|
|
|
* ) |
|
25
|
|
|
*/ |
|
26
|
|
|
class EntityRendered extends FieldPluginBase implements ContainerFactoryPluginInterface { |
|
27
|
|
|
use DependencySerializationTrait; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* The entity type manager service. |
|
31
|
|
|
* |
|
32
|
|
|
* @var \Drupal\Core\Entity\EntityTypeManagerInterface |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $entityTypeManager; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* The renderer service. |
|
38
|
|
|
* |
|
39
|
|
|
* @var \Drupal\Core\Render\RendererInterface |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $renderer; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritdoc} |
|
45
|
|
|
*/ |
|
46
|
|
|
public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) { |
|
47
|
|
|
return new static( |
|
48
|
|
|
$configuration, |
|
49
|
|
|
$pluginId, |
|
50
|
|
|
$pluginDefinition, |
|
51
|
|
|
$container->get('entity_type.manager'), |
|
52
|
|
|
$container->get('renderer') |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* EntityRendered constructor. |
|
58
|
|
|
* |
|
59
|
|
|
* @param array $configuration |
|
60
|
|
|
* The plugin configuration array. |
|
61
|
|
|
* @param string $pluginId |
|
62
|
|
|
* The plugin id. |
|
63
|
|
|
* @param mixed $pluginDefinition |
|
64
|
|
|
* The plugin definition. |
|
65
|
|
|
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager |
|
66
|
|
|
* The entity type manager service. |
|
67
|
|
|
* @param \Drupal\Core\Render\RendererInterface $renderer |
|
68
|
|
|
* The renderer service. |
|
69
|
|
|
*/ |
|
70
|
|
|
public function __construct( |
|
71
|
|
|
array $configuration, |
|
72
|
|
|
$pluginId, |
|
73
|
|
|
$pluginDefinition, |
|
74
|
|
|
EntityTypeManagerInterface $entityTypeManager, |
|
75
|
|
|
RendererInterface $renderer |
|
76
|
|
|
) { |
|
77
|
|
|
parent::__construct($configuration, $pluginId, $pluginDefinition); |
|
78
|
|
|
$this->entityTypeManager = $entityTypeManager; |
|
79
|
|
|
$this->renderer = $renderer; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* {@inheritdoc} |
|
84
|
|
|
*/ |
|
85
|
|
|
public function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) { |
|
86
|
|
|
if ($value instanceof ContentEntityInterface) { |
|
87
|
|
|
$mode = isset($args['mode']) ? $args['mode'] : 'full'; |
|
88
|
|
|
$language = $value->language()->getId(); |
|
89
|
|
|
$builder = $this->entityTypeManager->getViewBuilder($value->getEntityTypeId()); |
|
90
|
|
|
$view = $builder->view($value, $mode, $language); |
|
91
|
|
|
|
|
92
|
|
|
$context = new RenderContext(); |
|
93
|
|
|
/** @var \GraphQL\Executor\ExecutionResult|\GraphQL\Executor\ExecutionResult[] $result */ |
|
94
|
|
|
$result = $this->renderer->executeInRenderContext($context, function() use ($view) { |
|
95
|
|
|
return $this->renderer->render($view); |
|
96
|
|
|
}); |
|
97
|
|
|
|
|
98
|
|
|
if (!$context->isEmpty()) { |
|
99
|
|
|
yield new CacheableValue((string) $result, [$context->pop()]); |
|
100
|
|
|
} |
|
101
|
|
|
else { |
|
102
|
|
|
yield (string) $result; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|
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