1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\graphql_mutation\Plugin\Deriver\Mutations; |
4
|
|
|
|
5
|
|
|
use Drupal\Component\Plugin\Derivative\DeriverBase; |
6
|
|
|
use Drupal\Core\Entity\ContentEntityTypeInterface; |
7
|
|
|
use Drupal\Core\Entity\EntityTypeBundleInfoInterface; |
8
|
|
|
use Drupal\Core\Entity\EntityTypeManagerInterface; |
9
|
|
|
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; |
10
|
|
|
use Drupal\graphql\Utility\StringHelper; |
11
|
|
|
use Drupal\graphql_content_mutation\ContentEntityMutationSchemaConfig; |
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
13
|
|
|
|
14
|
|
|
class CreateEntityDeriver extends DeriverBase implements ContainerDeriverInterface { |
15
|
|
|
/** |
16
|
|
|
* The entity type manager service. |
17
|
|
|
* |
18
|
|
|
* @var \Drupal\Core\Entity\EntityTypeManagerInterface |
19
|
|
|
*/ |
20
|
|
|
protected $entityTypeManager; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The entity manager service. |
24
|
|
|
* |
25
|
|
|
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface |
26
|
|
|
*/ |
27
|
|
|
protected $entityTypeBundleInfo; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public static function create(ContainerInterface $container, $basePluginId) { |
33
|
|
|
return new static( |
34
|
|
|
$container->get('entity_type.bundle.info'), |
35
|
|
|
$container->get('entity_type.manager') |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
public function __construct( |
43
|
|
|
EntityTypeBundleInfoInterface $entityTypeBundleInfo, |
44
|
|
|
EntityTypeManagerInterface $entityTypeManager |
45
|
|
|
) { |
46
|
|
|
$this->entityTypeBundleInfo = $entityTypeBundleInfo; |
47
|
|
|
$this->entityTypeManager = $entityTypeManager; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
public function getDerivativeDefinitions($basePluginDefinition) { |
54
|
|
|
foreach ($this->entityTypeManager->getDefinitions() as $entityTypeId => $type) { |
55
|
|
|
if (!($type instanceof ContentEntityTypeInterface)) { |
|
|
|
|
56
|
|
|
continue; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
foreach ($this->entityTypeBundleInfo->getBundleInfo($entityTypeId) as $bundleName => $bundle) { |
60
|
|
|
$this->derivatives["$entityTypeId:$bundleName"] = [ |
61
|
|
|
'name' => StringHelper::propCase(['create', $entityTypeId, $bundleName]), |
62
|
|
|
'arguments' => [ |
63
|
|
|
'input' => [ |
64
|
|
|
'type' => StringHelper::camelCase([$entityTypeId, $bundleName, 'create', 'input']), |
65
|
|
|
'nullable' => FALSE, |
66
|
|
|
'multi' => FALSE, |
67
|
|
|
], |
68
|
|
|
], |
69
|
|
|
'entity_type' => $entityTypeId, |
70
|
|
|
'entity_bundle' => $bundleName, |
71
|
|
|
] + $basePluginDefinition; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return parent::getDerivativeDefinitions($basePluginDefinition); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.