EntityFieldDeriverBase::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Drupal\graphql_core\Plugin\Deriver;
4
5
use Drupal\Component\Plugin\Derivative\DeriverBase;
0 ignored issues
show
Bug introduced by
The type Drupal\Component\Plugin\Derivative\DeriverBase was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\DependencyIn...dencySerializationTrait was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Entity\EntityTypeBundleInfoInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Drupal\Core\Entity\EntityTypeManagerInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Entity\EntityTypeManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Drupal\Core\Entity\FieldableEntityInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Entity\FieldableEntityInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Drupal\Core\Field\FieldDefinitionInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Field\FieldDefinitionInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Drupal\Core\Field\FieldStorageDefinitionInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Field\FieldStorageDefinitionInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Plugin\Disco...ntainerDeriverInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Drupal\Core\Entity\EntityFieldManagerInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Entity\EntityFieldManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Symfony\Component\DependencyInjection\ContainerInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...tion\ContainerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
16
/**
17
 * Generate GraphQLField plugins for config fields.
18
 */
19
abstract class EntityFieldDeriverBase extends DeriverBase implements ContainerDeriverInterface {
20
  use DependencySerializationTrait;
21
22
  /**
23
   * Provides plugin definition values from fields.
24
   *
25
   * @param \Drupal\Core\Field\FieldDefinitionInterface $fieldDefinition
26
   *   Field definition object.
27
   * @param array $basePluginDefinition
28
   *   Base definition array.
29
   *
30
   * @return array
31
   *   The derived plugin definitions for the given field.
32
   */
33
  abstract protected function getDerivativeDefinitionsFromFieldDefinition(FieldDefinitionInterface $fieldDefinition, array $basePluginDefinition);
34
35
  /**
36
   * The entity type manager.
37
   *
38
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
39
   */
40
  protected $entityTypeManager;
41
42
  /**
43
   * The entity field manager.
44
   *
45
   * @var \Drupal\Core\Entity\EntityFieldManagerInterface
46
   */
47
  protected $entityFieldManager;
48
49
  /**
50
   * The entity bundle info.
51
   *
52
   * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
53
   */
54
  protected $entityBundleInfo;
55
56
  /**
57
   * The base plugin id.
58
   *
59
   * @var string
60
   */
61
  protected $basePluginId;
62
63
  /**
64
   * {@inheritdoc}
65
   */
66
  public static function create(ContainerInterface $container, $basePluginId) {
67
    return new static(
68
      $container->get('entity_type.manager'),
69
      $container->get('entity_field.manager'),
70
      $container->get('entity_type.bundle.info'),
71
      $basePluginId
72
    );
73
  }
74
75
  /**
76
   * RawValueFieldItemDeriver constructor.
77
   *
78
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
79
   *   The entity type manager.
80
   * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager
81
   *   The entity field manager.
82
   * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entityTypeBundleInfo
83
   *   The bundle info service.
84
   * @param string $basePluginId
85
   *   The base plugin id.
86
   */
87
  public function __construct(
88
    EntityTypeManagerInterface $entityTypeManager,
89
    EntityFieldManagerInterface $entityFieldManager,
90
    EntityTypeBundleInfoInterface $entityTypeBundleInfo,
91
    $basePluginId
92
  ) {
93
    $this->basePluginId = $basePluginId;
94
    $this->entityTypeManager = $entityTypeManager;
95
    $this->entityFieldManager = $entityFieldManager;
96
    $this->entityBundleInfo = $entityTypeBundleInfo;
97
  }
98
99
  /**
100
   * {@inheritdoc}
101
   */
102
  public function getDerivativeDefinitions($basePluginDefinition) {
103
    foreach ($this->entityTypeManager->getDefinitions() as $entityTypeId => $entityType) {
104
      if (!$entityType->entityClassImplements(FieldableEntityInterface::class)) {
105
        continue;
106
      }
107
108
      foreach ($this->entityFieldManager->getBaseFieldDefinitions($entityTypeId) as $fieldDefinition) {
109
        if ($derivatives = $this->getDerivativeDefinitionsFromFieldDefinition($fieldDefinition, $basePluginDefinition)) {
110
          $this->derivatives = array_merge($this->derivatives, $derivatives);
0 ignored issues
show
Bug Best Practice introduced by
The property derivatives does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
111
        }
112
      }
113
114
      foreach ($this->entityBundleInfo->getBundleInfo($entityTypeId) as $bundleId => $bundleInfo) {
115
        foreach ($this->entityFieldManager->getFieldDefinitions($entityTypeId, $bundleId) as $fieldDefinition) {
116
          if ($derivatives = $this->getDerivativeDefinitionsFromFieldDefinition($fieldDefinition, $basePluginDefinition)) {
117
            $this->derivatives = array_merge($this->derivatives, $derivatives);
118
          }
119
        }
120
      }
121
    }
122
123
    return $this->derivatives;
124
  }
125
126
}
127