Completed
Pull Request — 8.x-3.x (#686)
by Sebastian
02:07
created

EntityFieldPropertyDeriver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDerivativeDefinitionsFromFieldDefinition() 0 19 5
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
    $entityTypeId = $fieldDefinition->getTargetEntityTypeId();
17
18
    $parents = [];
19
    if (isset($basePluginDefinition['field_types']) && in_array($fieldType, $basePluginDefinition['field_types'])) {
20
      $fieldName = $fieldDefinition->getName();
21
      $fieldBundle = $fieldDefinition->getTargetBundle() ?: '';
22
      $parents[] = StringHelper::camelCase('field', $entityTypeId, $fieldBundle, $fieldName);
23
    }
24
25
    if (!empty($parents)) {
26
      $this->derivatives[$basePluginDefinition['id']] = [
27
        'parents' => array_merge($parents, $basePluginDefinition['parents']),
28
      ] + $basePluginDefinition;
29
    }
30
31
    return $this->derivatives;
32
  }
33
}