Completed
Push — 8.x-3.x ( 6b97f3...bd3169 )
by Philipp
02:30
created

EntityFieldPropertyDeriver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDerivativeDefinitionsFromFieldDefinition() 0 17 3
1
<?php
2
3
namespace Drupal\graphql_core\Plugin\Deriver\Fields;
4
5
use Drupal\Core\Field\FieldStorageDefinitionInterface;
6
use Drupal\graphql_core\Plugin\Deriver\EntityFieldDeriverWithTypeMapping;
7
use Drupal\graphql_core\Plugin\GraphQL\Types\Entity\EntityFieldType;
8
9
/**
10
 * Attach new properties to field types.
11
 */
12
class EntityFieldPropertyDeriver extends EntityFieldDeriverWithTypeMapping {
13
14
  protected function getDerivativeDefinitionsFromFieldDefinition(
15
    $entityTypeId,
16
    FieldStorageDefinitionInterface $fieldDefinition,
17
    array $basePluginDefinition
18
  ) {
19
20
    $derivatives = [];
21
22
    if (isset($basePluginDefinition['field_types']) && in_array($fieldDefinition->getType(), $basePluginDefinition['field_types'])) {
23
      $fieldName = $fieldDefinition->getName();
24
      $derivatives["$entityTypeId-$fieldName-" . $basePluginDefinition['id']] = [
25
        'parents' => [EntityFieldType::getId($entityTypeId, $fieldName)]
26
      ] + $basePluginDefinition;
27
    }
28
29
    return $derivatives;
30
  }
31
32
}