|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\graphql_core\Plugin\GraphQL\Fields\Breadcrumbs; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Core\Breadcrumb\BreadcrumbManager; |
|
|
|
|
|
|
6
|
|
|
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; |
|
|
|
|
|
|
7
|
|
|
use Drupal\Core\Routing\RouteMatchInterface; |
|
|
|
|
|
|
8
|
|
|
use Drupal\Core\Url; |
|
|
|
|
|
|
9
|
|
|
use Drupal\graphql\GraphQL\Buffers\SubRequestBuffer; |
|
10
|
|
|
use Drupal\graphql\GraphQL\Cache\CacheableValue; |
|
11
|
|
|
use Drupal\graphql\GraphQL\Execution\ResolveContext; |
|
12
|
|
|
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
|
|
|
|
14
|
|
|
use GraphQL\Type\Definition\ResolveInfo; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Retrieve the breadcrumbs. |
|
18
|
|
|
* |
|
19
|
|
|
* @GraphQLField( |
|
20
|
|
|
* id = "breadcrumb", |
|
21
|
|
|
* secure = true, |
|
22
|
|
|
* name = "breadcrumb", |
|
23
|
|
|
* type = "[Link]", |
|
24
|
|
|
* parents = {"InternalUrl"}, |
|
25
|
|
|
* ) |
|
26
|
|
|
*/ |
|
27
|
|
|
class Breadcrumbs extends FieldPluginBase implements ContainerFactoryPluginInterface { |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* The subrequest buffer service. |
|
31
|
|
|
* |
|
32
|
|
|
* @var \Drupal\graphql\GraphQL\Buffers\SubRequestBuffer |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $subRequestBuffer; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* The breadcrumb manager service. |
|
38
|
|
|
* |
|
39
|
|
|
* @var \Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface |
|
|
|
|
|
|
40
|
|
|
*/ |
|
41
|
|
|
protected $breadcrumbManager; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* The current route match. |
|
45
|
|
|
* |
|
46
|
|
|
* @var \Drupal\Core\Routing\RouteMatchInterface |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $routeMatch; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* {@inheritdoc} |
|
52
|
|
|
*/ |
|
53
|
|
|
public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) { |
|
54
|
|
|
return new static( |
|
55
|
|
|
$configuration, |
|
56
|
|
|
$pluginId, |
|
57
|
|
|
$pluginDefinition, |
|
58
|
|
|
$container->get('graphql.buffer.subrequest'), |
|
59
|
|
|
$container->get('breadcrumb'), |
|
60
|
|
|
$container->get('current_route_match') |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Breadcrumbs constructor. |
|
66
|
|
|
* |
|
67
|
|
|
* @param array $configuration |
|
68
|
|
|
* The plugin configuration array. |
|
69
|
|
|
* @param string $pluginId |
|
70
|
|
|
* The plugin id. |
|
71
|
|
|
* @param mixed $pluginDefinition |
|
72
|
|
|
* The plugin definition. |
|
73
|
|
|
* @param \Drupal\graphql\GraphQL\Buffers\SubRequestBuffer $subRequestBuffer |
|
74
|
|
|
* The sub-request buffer service. |
|
75
|
|
|
* @param \Drupal\Core\Breadcrumb\BreadcrumbManager $breadcrumbManager |
|
76
|
|
|
* The breadcrumb manager service. |
|
77
|
|
|
* @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch |
|
78
|
|
|
* The current route match. |
|
79
|
|
|
*/ |
|
80
|
|
|
public function __construct( |
|
81
|
|
|
array $configuration, |
|
82
|
|
|
$pluginId, |
|
83
|
|
|
$pluginDefinition, |
|
84
|
|
|
SubRequestBuffer $subRequestBuffer, |
|
85
|
|
|
BreadcrumbManager $breadcrumbManager, |
|
86
|
|
|
RouteMatchInterface $routeMatch |
|
87
|
|
|
) { |
|
88
|
|
|
parent::__construct($configuration, $pluginId, $pluginDefinition); |
|
89
|
|
|
$this->subRequestBuffer = $subRequestBuffer; |
|
90
|
|
|
$this->breadcrumbManager = $breadcrumbManager; |
|
91
|
|
|
$this->routeMatch = $routeMatch; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* {@inheritdoc} |
|
96
|
|
|
*/ |
|
97
|
|
|
protected function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) { |
|
98
|
|
|
if ($value instanceof Url) { |
|
99
|
|
|
$resolve = $this->subRequestBuffer->add($value, function () { |
|
100
|
|
|
$links = $this->breadcrumbManager->build($this->routeMatch)->getLinks(); |
|
101
|
|
|
return $links; |
|
102
|
|
|
}); |
|
103
|
|
|
|
|
104
|
|
|
return function ($value, array $args, ResolveContext $context, ResolveInfo $info) use ($resolve) { |
|
|
|
|
|
|
105
|
|
|
/** @var \Drupal\graphql\GraphQL\Cache\CacheableValue $response */ |
|
106
|
|
|
$response = $resolve(); |
|
107
|
|
|
$links = $response->getValue(); |
|
108
|
|
|
|
|
109
|
|
|
foreach ($links as $link) { |
|
110
|
|
|
yield new CacheableValue($link, [$response]); |
|
111
|
|
|
} |
|
112
|
|
|
}; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
} |
|
117
|
|
|
|
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