You are here

class EntityFieldDeriver in GraphQL 8.3

Hierarchy

Expanded class hierarchy of EntityFieldDeriver

File

modules/graphql_core/src/Plugin/Deriver/Fields/EntityFieldDeriver.php, line 11

Namespace

Drupal\graphql_core\Plugin\Deriver\Fields
View source
class EntityFieldDeriver extends EntityFieldDeriverBase {

  /**
   * {@inheritdoc}
   */
  protected function getDerivativeDefinitionsFromFieldDefinition(FieldDefinitionInterface $fieldDefinition, array $basePluginDefinition) {
    $itemDefinition = $fieldDefinition
      ->getItemDefinition();
    if (!$itemDefinition instanceof ComplexDataDefinitionInterface || !($propertyDefinitions = $itemDefinition
      ->getPropertyDefinitions())) {
      return [];
    }
    $tags = array_merge($fieldDefinition
      ->getCacheTags(), [
      'entity_field_info',
    ]);
    $maxAge = $fieldDefinition
      ->getCacheMaxAge();
    $contexts = $fieldDefinition
      ->getCacheContexts();
    $entityTypeId = $fieldDefinition
      ->getTargetEntityTypeId();
    $entityType = $this->entityTypeManager
      ->getDefinition($entityTypeId);
    $supportsBundles = $entityType
      ->hasKey('bundle');
    $fieldName = $fieldDefinition
      ->getName();
    $fieldBundle = $fieldDefinition
      ->getTargetBundle() ?: '';
    $derivative = [
      'parents' => [
        StringHelper::camelCase($entityTypeId, $supportsBundles ? $fieldBundle : ''),
      ],
      'name' => StringHelper::propCase($fieldName),
      'description' => $fieldDefinition
        ->getDescription(),
      'field' => $fieldName,
      'schema_cache_tags' => $tags,
      'schema_cache_contexts' => $contexts,
      'schema_cache_max_age' => $maxAge,
    ] + $basePluginDefinition;
    if (count($propertyDefinitions) === 1) {
      $propertyDefinition = reset($propertyDefinitions);
      $derivative['type'] = $propertyDefinition
        ->getDataType();
      $derivative['property'] = key($propertyDefinitions);
    }
    else {
      $derivative['type'] = StringHelper::camelCase('field', $entityTypeId, $supportsBundles ? $fieldBundle : '', $fieldName);
    }

    // Fields are usually multi-value. Simplify them for the schema if they are
    // configured for cardinality 1 (only works for configured fields).
    if (!(($storageDefinition = $fieldDefinition
      ->getFieldStorageDefinition()) && !$storageDefinition
      ->isMultiple())) {
      $derivative['type'] = StringHelper::listType($derivative['type']);
    }
    return [
      "{$entityTypeId}-{$fieldName}-{$fieldBundle}" => $derivative,
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
EntityFieldDeriver::getDerivativeDefinitionsFromFieldDefinition protected function Provides plugin definition values from fields. Overrides EntityFieldDeriverBase::getDerivativeDefinitionsFromFieldDefinition
EntityFieldDeriverBase::$basePluginId protected property The base plugin id.
EntityFieldDeriverBase::$entityBundleInfo protected property The entity bundle info.
EntityFieldDeriverBase::$entityFieldManager protected property The entity field manager.
EntityFieldDeriverBase::$entityTypeManager protected property The entity type manager.
EntityFieldDeriverBase::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
EntityFieldDeriverBase::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
EntityFieldDeriverBase::__construct public function RawValueFieldItemDeriver constructor.