@@ 13-64 (lines=52) @@ | ||
10 | use Drupal\graphql\Utility\StringHelper; |
|
11 | use Symfony\Component\DependencyInjection\ContainerInterface; |
|
12 | ||
13 | class EntityByIdDeriver extends DeriverBase implements ContainerDeriverInterface { |
|
14 | ||
15 | use StringTranslationTrait; |
|
16 | ||
17 | /** |
|
18 | * The entity type manager service. |
|
19 | * |
|
20 | * @var \Drupal\Core\Entity\EntityTypeManagerInterface |
|
21 | */ |
|
22 | protected $entityTypeManager; |
|
23 | ||
24 | /** |
|
25 | * {@inheritdoc} |
|
26 | */ |
|
27 | public static function create(ContainerInterface $container, $basePluginId) { |
|
28 | return new static($container->get('entity_type.manager')); |
|
29 | } |
|
30 | ||
31 | /** |
|
32 | * {@inheritdoc} |
|
33 | */ |
|
34 | public function __construct(EntityTypeManagerInterface $entityTypeManager) { |
|
35 | $this->entityTypeManager = $entityTypeManager; |
|
36 | } |
|
37 | ||
38 | /** |
|
39 | * {@inheritdoc} |
|
40 | */ |
|
41 | public function getDerivativeDefinitions($basePluginDefinition) { |
|
42 | foreach ($this->entityTypeManager->getDefinitions() as $id => $type) { |
|
43 | if ($type instanceof ContentEntityTypeInterface) { |
|
44 | $derivative = [ |
|
45 | 'name' => StringHelper::propCase($id, 'by', 'id'), |
|
46 | 'type' => "entity:$id", |
|
47 | 'description' => $this->t("Loads '@type' entities by their id.", ['@type' => $type->getLabel()]), |
|
48 | 'entity_type' => $id, |
|
49 | ] + $basePluginDefinition; |
|
50 | ||
51 | if ($type->isTranslatable()) { |
|
52 | $derivative['arguments']['language'] = [ |
|
53 | 'type' => 'LanguageId', |
|
54 | ]; |
|
55 | } |
|
56 | ||
57 | $this->derivatives["entity:$id"] = $derivative; |
|
58 | } |
|
59 | } |
|
60 | ||
61 | return parent::getDerivativeDefinitions($basePluginDefinition); |
|
62 | } |
|
63 | ||
64 | } |
|
65 |
@@ 13-64 (lines=52) @@ | ||
10 | use Drupal\graphql\Utility\StringHelper; |
|
11 | use Symfony\Component\DependencyInjection\ContainerInterface; |
|
12 | ||
13 | class EntityRevisionByIdDeriver extends DeriverBase implements ContainerDeriverInterface { |
|
14 | ||
15 | use StringTranslationTrait; |
|
16 | ||
17 | /** |
|
18 | * The entity type manager service. |
|
19 | * |
|
20 | * @var \Drupal\Core\Entity\EntityTypeManagerInterface |
|
21 | */ |
|
22 | protected $entityTypeManager; |
|
23 | ||
24 | /** |
|
25 | * {@inheritdoc} |
|
26 | */ |
|
27 | public static function create(ContainerInterface $container, $basePluginId) { |
|
28 | return new static($container->get('entity_type.manager')); |
|
29 | } |
|
30 | ||
31 | /** |
|
32 | * {@inheritdoc} |
|
33 | */ |
|
34 | public function __construct(EntityTypeManagerInterface $entityTypeManager) { |
|
35 | $this->entityTypeManager = $entityTypeManager; |
|
36 | } |
|
37 | ||
38 | /** |
|
39 | * {@inheritdoc} |
|
40 | */ |
|
41 | public function getDerivativeDefinitions($basePluginDefinition) { |
|
42 | foreach ($this->entityTypeManager->getDefinitions() as $id => $type) { |
|
43 | if ($type instanceof ContentEntityTypeInterface && $type->isRevisionable()) { |
|
44 | $derivative = [ |
|
45 | 'name' => StringHelper::propCase($id, 'revision', 'by', 'id'), |
|
46 | 'type' => "entity:$id", |
|
47 | 'description' => $this->t("Loads '@type' entity revision by their revision id.", ['@type' => $type->getLabel()]), |
|
48 | 'entity_type' => $id, |
|
49 | ] + $basePluginDefinition; |
|
50 | ||
51 | if ($type->isTranslatable()) { |
|
52 | $derivative['arguments']['language'] = [ |
|
53 | 'type' => 'LanguageId', |
|
54 | ]; |
|
55 | } |
|
56 | ||
57 | $this->derivatives["entity:$id"] = $derivative; |
|
58 | } |
|
59 | } |
|
60 | ||
61 | return parent::getDerivativeDefinitions($basePluginDefinition); |
|
62 | } |
|
63 | ||
64 | } |
|
65 |