|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\graphql_core\Plugin\Deriver\Enums; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Component\Plugin\Derivative\DeriverBase; |
|
|
|
|
|
|
6
|
|
|
use Drupal\Core\Entity\EntityTypeManagerInterface; |
|
|
|
|
|
|
7
|
|
|
use Drupal\Core\Entity\EntityViewModeInterface; |
|
|
|
|
|
|
8
|
|
|
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; |
|
|
|
|
|
|
9
|
|
|
use Drupal\Core\StringTranslation\StringTranslationTrait; |
|
|
|
|
|
|
10
|
|
|
use Drupal\graphql\Utility\StringHelper; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class DisplayModeIdDeriver extends DeriverBase implements ContainerDeriverInterface { |
|
14
|
|
|
use StringTranslationTrait; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Entity type manager. |
|
18
|
|
|
* |
|
19
|
|
|
* @var \Drupal\Core\Entity\EntityTypeManagerInterface |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $entityTypeManager; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
*/ |
|
26
|
|
|
public static function create(ContainerInterface $container, $basePluginId) { |
|
27
|
|
|
return new static($container->get('entity_type.manager')); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* DisplayModeIdDeriver constructor. |
|
32
|
|
|
* |
|
33
|
|
|
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager |
|
34
|
|
|
* The entity type manager service. |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct(EntityTypeManagerInterface $entityTypeManager) { |
|
37
|
|
|
$this->entityTypeManager = $entityTypeManager; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritdoc} |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getDerivativeDefinitions($basePluginDefinition) { |
|
44
|
|
|
foreach ($this->getDisplayModes() as $targetType => $displayModes) { |
|
45
|
|
|
$this->derivatives[$targetType] = [ |
|
|
|
|
|
|
46
|
|
|
'name' => StringHelper::camelCase($targetType, 'display', 'mode', 'id'), |
|
47
|
|
|
'description' => $this->t("The available display modes for '@type' entities.", [ |
|
48
|
|
|
'@type' => $this->entityTypeManager->getDefinition($targetType)->getLabel(), |
|
49
|
|
|
]), |
|
50
|
|
|
'values' => $displayModes, |
|
51
|
|
|
] + $basePluginDefinition; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return parent::getDerivativeDefinitions($basePluginDefinition); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Retrieves a list of entity view modes grouped by their target type. |
|
59
|
|
|
* |
|
60
|
|
|
* @return array |
|
61
|
|
|
* The list of entity view modes grouped by the target entity type. |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function getDisplayModes() { |
|
64
|
|
|
$storage = $this->entityTypeManager->getStorage('entity_view_mode'); |
|
65
|
|
|
return array_reduce($storage->loadMultiple(), function ($carry, EntityViewModeInterface $current) { |
|
66
|
|
|
$target = $current->getTargetType(); |
|
67
|
|
|
list(, $id) = explode('.', $current->id()); |
|
68
|
|
|
|
|
69
|
|
|
$carry[$target][StringHelper::upperCase($id)] = [ |
|
70
|
|
|
'value' => $id, |
|
71
|
|
|
'description' => $this->t("The '@label' display mode for '@type' entities.", [ |
|
72
|
|
|
'@label' => $current->label(), |
|
73
|
|
|
'@type' => $this->entityTypeManager->getDefinition($target)->getLabel(), |
|
74
|
|
|
]), |
|
75
|
|
|
]; |
|
76
|
|
|
|
|
77
|
|
|
return $carry; |
|
78
|
|
|
}, []); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|
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