You are here

public function DefaultValue::resolve in GraphQL 8.4

Same name in this branch
  1. 8.4 src/GraphQL/Resolver/DefaultValue.php \Drupal\graphql\GraphQL\Resolver\DefaultValue::resolve()
  2. 8.4 src/Plugin/GraphQL/DataProducer/EntityDefinition/Fields/DefaultValue.php \Drupal\graphql\Plugin\GraphQL\DataProducer\EntityDefinition\Fields\DefaultValue::resolve()

Resolves the default value property.

Parameters

\Drupal\Core\Field\FieldDefinitionInterface $entity_definition_field: The entity field definition.

Return value

string|bool|int|null The default value.

File

src/Plugin/GraphQL/DataProducer/EntityDefinition/Fields/DefaultValue.php, line 36

Class

DefaultValue
Retrieves the "default_value" property from a given field definition.

Namespace

Drupal\graphql\Plugin\GraphQL\DataProducer\EntityDefinition\Fields

Code

public function resolve(FieldDefinitionInterface $entity_definition_field) {
  $default_value = $entity_definition_field
    ->getDefaultValueLiteral();
  switch ($entity_definition_field
    ->getType()) {
    case 'list_integer':
    case 'list_string':
    case 'text_long':
      return $default_value[0]['value'] ?? NULL;
    case 'boolean':
      return (bool) ($default_value[0]['value'] ?? FALSE);
  }
  return NULL;
}