1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\graphql_core\Plugin\GraphQL\Fields\Menu; |
4
|
|
|
|
5
|
|
|
use Drupal\Core\DependencyInjection\DependencySerializationTrait; |
|
|
|
|
6
|
|
|
use Drupal\Core\Menu\MenuLinkInterface; |
|
|
|
|
7
|
|
|
use Drupal\Core\Menu\MenuLinkTreeElement; |
|
|
|
|
8
|
|
|
use Drupal\Core\Menu\MenuLinkTreeInterface; |
|
|
|
|
9
|
|
|
use Drupal\Core\Menu\MenuTreeParameters; |
|
|
|
|
10
|
|
|
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; |
|
|
|
|
11
|
|
|
use Drupal\graphql\GraphQL\Execution\ResolveContext; |
12
|
|
|
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase; |
13
|
|
|
use Drupal\system\MenuInterface; |
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
|
|
15
|
|
|
use GraphQL\Type\Definition\ResolveInfo; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Retrieves a menus links. |
19
|
|
|
* |
20
|
|
|
* @GraphQLField( |
21
|
|
|
* id = "menu_links", |
22
|
|
|
* secure = true, |
23
|
|
|
* name = "links", |
24
|
|
|
* type = "[MenuLink]", |
25
|
|
|
* parents = {"Menu"}, |
26
|
|
|
* response_cache_contexts = {"languages:language_url"} |
27
|
|
|
* ) |
28
|
|
|
*/ |
29
|
|
|
class MenuLinks extends FieldPluginBase implements ContainerFactoryPluginInterface { |
30
|
|
|
use DependencySerializationTrait; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The menu link tree. |
34
|
|
|
* |
35
|
|
|
* @var \Drupal\Core\Menu\MenuLinkTreeInterface |
36
|
|
|
*/ |
37
|
|
|
protected $menuLinkTree; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) { |
43
|
|
|
return new static($configuration, $pluginId, $pluginDefinition, $container->get('menu.link_tree')); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* MenuLinks constructor. |
48
|
|
|
* |
49
|
|
|
* @param array $configuration |
50
|
|
|
* The plugin configuration array. |
51
|
|
|
* @param string $pluginId |
52
|
|
|
* The plugin id. |
53
|
|
|
* @param mixed $pluginDefinition |
54
|
|
|
* The plugin definition. |
55
|
|
|
* @param \Drupal\Core\Menu\MenuLinkTreeInterface $menuLinkTree |
56
|
|
|
* The menu link tree service. |
57
|
|
|
*/ |
58
|
|
|
public function __construct(array $configuration, $pluginId, $pluginDefinition, MenuLinkTreeInterface $menuLinkTree) { |
59
|
|
|
parent::__construct($configuration, $pluginId, $pluginDefinition); |
60
|
|
|
$this->menuLinkTree = $menuLinkTree; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
|
|
public function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) { |
67
|
|
|
if ($value instanceof MenuInterface) { |
68
|
|
|
$tree = $this->menuLinkTree->load($value->id(), new MenuTreeParameters()); |
69
|
|
|
|
70
|
|
|
$manipulators = [ |
71
|
|
|
['callable' => 'menu.default_tree_manipulators:checkAccess'], |
72
|
|
|
['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'], |
73
|
|
|
]; |
74
|
|
|
|
75
|
|
|
foreach (array_filter($this->menuLinkTree->transform($tree, $manipulators), function (MenuLinkTreeElement $item) { |
76
|
|
|
return $item->link instanceof MenuLinkInterface && $item->link->isEnabled() && (empty($item->access) || $item->access->isAllowed()); |
77
|
|
|
}) as $branch) { |
78
|
|
|
yield $branch; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
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