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

getDerivativeDefinitionsFromFieldDefinition()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 2
dl 0
loc 15
rs 9.7666
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
    if (isset($basePluginDefinition['field_types']) && in_array($fieldType, $basePluginDefinition['field_types'])) {
19
      $fieldName = $fieldDefinition->getName();
20
      $fieldBundle = $fieldDefinition->getTargetBundle() ?: '';
21
22
      return ["$entityTypeId-$fieldBundle-$fieldName" => [
23
        'parents' => [StringHelper::camelCase('field', $entityTypeId, $fieldBundle, $fieldName)],
24
      ] + $basePluginDefinition];
25
    }
26
27
    return [];
28
  }
29
}