You are here

protected function EntityFieldBase::resolveItem in GraphQL 8.3

2 calls to EntityFieldBase::resolveItem()
EntityField::resolveValues in modules/graphql_core/src/Plugin/GraphQL/Fields/Entity/EntityField.php
Retrieve the list of field values.
EntityFieldItem::resolveValues in modules/graphql_core/src/Plugin/GraphQL/Fields/Entity/EntityFieldItem.php
Retrieve the list of field values.

File

modules/graphql_core/src/Plugin/GraphQL/Fields/EntityFieldBase.php, line 24

Class

EntityFieldBase
Base class for entity field plugins.

Namespace

Drupal\graphql_core\Plugin\GraphQL\Fields

Code

protected function resolveItem($item, array $args, ResolveContext $context, ResolveInfo $info) {
  if ($item instanceof FieldItemInterface) {
    $definition = $this
      ->getPluginDefinition();
    $property = $definition['property'];
    $result = $item
      ->get($property)
      ->getValue();
    $result = $result instanceof MarkupInterface ? $result
      ->__toString() : $result;
    $type = $info->returnType;
    $type = $type instanceof WrappingType ? $type
      ->getWrappedType(TRUE) : $type;
    if ($type instanceof ScalarType) {
      $result = is_null($result) ? NULL : $type
        ->serialize($result);
    }
    if ($result instanceof ContentEntityInterface && $result
      ->isTranslatable() && ($language = $context
      ->getContext('language', $info))) {
      if ($result
        ->hasTranslation($language)) {
        $result = $result
          ->getTranslation($language);
      }
    }
    return $result;
  }
}