@@ 15-60 (lines=46) @@ | ||
12 | /** |
|
13 | * Derive GraphQL Interfaces from Drupal entity types. |
|
14 | */ |
|
15 | class EntityTypeDeriver extends DeriverBase implements ContainerDeriverInterface { |
|
16 | ||
17 | /** |
|
18 | * The entity type manager. |
|
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( |
|
29 | $container->get('entity_type.manager') |
|
30 | ); |
|
31 | } |
|
32 | ||
33 | /** |
|
34 | * EntityTypeDeriver constructor. |
|
35 | * |
|
36 | * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager |
|
37 | * Instance of an entity type manager. |
|
38 | */ |
|
39 | public function __construct(EntityTypeManagerInterface $entityTypeManager) { |
|
40 | $this->entityTypeManager = $entityTypeManager; |
|
41 | } |
|
42 | ||
43 | /** |
|
44 | * {@inheritdoc} |
|
45 | */ |
|
46 | public function getDerivativeDefinitions($basePluginDefinition) { |
|
47 | $this->derivatives = []; |
|
48 | foreach ($this->entityTypeManager->getDefinitions() as $typeId => $type) { |
|
49 | if ($type instanceof ContentEntityTypeInterface) { |
|
50 | $this->derivatives[$typeId] = [ |
|
51 | 'name' => StringHelper::camelCase($typeId), |
|
52 | 'data_type' => 'entity:' . $typeId, |
|
53 | 'entity_type' => $typeId, |
|
54 | ] + $basePluginDefinition; |
|
55 | } |
|
56 | } |
|
57 | return parent::getDerivativeDefinitions($basePluginDefinition); |
|
58 | } |
|
59 | ||
60 | } |
|
61 |
@@ 13-57 (lines=45) @@ | ||
10 | use Drupal\graphql_content_mutation\ContentEntityMutationSchemaConfig; |
|
11 | use Symfony\Component\DependencyInjection\ContainerInterface; |
|
12 | ||
13 | class DeleteEntityDeriver extends DeriverBase implements ContainerDeriverInterface { |
|
14 | /** |
|
15 | * The entity type manager service. |
|
16 | * |
|
17 | * @var \Drupal\Core\Entity\EntityTypeManagerInterface |
|
18 | */ |
|
19 | protected $entityTypeManager; |
|
20 | ||
21 | /** |
|
22 | * {@inheritdoc} |
|
23 | */ |
|
24 | public static function create(ContainerInterface $container, $basePluginId) { |
|
25 | return new static( |
|
26 | $container->get('entity_type.manager') |
|
27 | ); |
|
28 | } |
|
29 | ||
30 | /** |
|
31 | * {@inheritdoc} |
|
32 | */ |
|
33 | public function __construct( |
|
34 | EntityTypeManagerInterface $entityTypeManager |
|
35 | ) { |
|
36 | $this->entityTypeManager = $entityTypeManager; |
|
37 | } |
|
38 | /** |
|
39 | * {@inheritdoc} |
|
40 | */ |
|
41 | public function getDerivativeDefinitions($basePluginDefinition) { |
|
42 | foreach ($this->entityTypeManager->getDefinitions() as $entityTypeId => $type) { |
|
43 | ||
44 | if (!($type instanceof ContentEntityTypeInterface)) { |
|
45 | continue; |
|
46 | } |
|
47 | ||
48 | $this->derivatives[$entityTypeId] = [ |
|
49 | 'name' => 'delete' . StringHelper::camelCase($entityTypeId), |
|
50 | 'entity_type' => $entityTypeId, |
|
51 | ] + $basePluginDefinition; |
|
52 | } |
|
53 | ||
54 | return parent::getDerivativeDefinitions($basePluginDefinition); |
|
55 | } |
|
56 | ||
57 | } |
|
58 |