Completed
Pull Request — 8.x-3.x (#684)
by Sebastian
13:11
created

EntityFieldPropertyDeriver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql_core\Plugin\Deriver\Fields;
4
5
use Drupal\Core\Field\FieldDefinitionInterface;
6
use Drupal\graphql\Utility\StringHelper;
7
use Drupal\graphql_core\Plugin\Deriver\EntityFieldDeriverBase;
8
9
class EntityFieldPropertyDeriver extends EntityFieldDeriverBase {
10
11
  /**
12
   * {@inheritdoc}
13
   */
14
  protected function getDerivativeDefinitionsFromFieldDefinition(FieldDefinitionInterface $fieldDefinition, array $basePluginDefinition) {
15
    $fieldType = $fieldDefinition->getType();
16
17
    if (isset($basePluginDefinition['field_types']) && in_array($fieldType, $basePluginDefinition['field_types'])) {
18
      $fieldName = $fieldDefinition->getName();
19
      $fieldBundle = $fieldDefinition->getTargetBundle() ?: '';
20
      $entityTypeId = $fieldDefinition->getTargetEntityTypeId();
21
      $entityType = $this->entityTypeManager->getDefinition($entityTypeId);
22
      $supportsBundles = $entityType->hasKey('bundle');
23
24
      return ["$entityTypeId-$fieldBundle-$fieldName" => [
25
        'parents' => [StringHelper::camelCase('field', $entityTypeId, $supportsBundles ? $fieldBundle : '', $fieldName)],
26
      ] + $basePluginDefinition];
27
    }
28
29
    return [];
30
  }
31
}