You are here

protected function EntityFieldPropertyDeriver::getDerivativeDefinitionsFromFieldDefinition in GraphQL 8.3

Provides plugin definition values from fields.

Parameters

\Drupal\Core\Field\FieldDefinitionInterface $fieldDefinition: Field definition object.

array $basePluginDefinition: Base definition array.

Return value

array The derived plugin definitions for the given field.

Overrides EntityFieldDeriverBase::getDerivativeDefinitionsFromFieldDefinition

File

modules/graphql_core/src/Plugin/Deriver/Fields/EntityFieldPropertyDeriver.php, line 14

Class

EntityFieldPropertyDeriver

Namespace

Drupal\graphql_core\Plugin\Deriver\Fields

Code

protected function getDerivativeDefinitionsFromFieldDefinition(FieldDefinitionInterface $fieldDefinition, array $basePluginDefinition) {
  $fieldType = $fieldDefinition
    ->getType();
  if (isset($basePluginDefinition['field_types']) && in_array($fieldType, $basePluginDefinition['field_types'])) {
    $fieldName = $fieldDefinition
      ->getName();
    $fieldBundle = $fieldDefinition
      ->getTargetBundle() ?: '';
    $entityTypeId = $fieldDefinition
      ->getTargetEntityTypeId();
    $entityType = $this->entityTypeManager
      ->getDefinition($entityTypeId);
    $supportsBundles = $entityType
      ->hasKey('bundle');
    if (!isset($basePluginDefinition['parents'])) {
      $basePluginDefinition['parents'] = [];
    }
    $parents = [
      StringHelper::camelCase('field', $entityTypeId, $supportsBundles ? $fieldBundle : '', $fieldName),
    ];
    return [
      "{$entityTypeId}-{$fieldBundle}-{$fieldName}" => [
        'parents' => array_merge($parents, $basePluginDefinition['parents']),
      ] + $basePluginDefinition,
    ];
  }
  return [];
}