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

getDerivativeDefinitionsFromFieldDefinition()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 6
nop 2
dl 0
loc 19
rs 9.3222
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
    $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
}