public function Field::resolve in Open Social 10.1.x
Same name and namespace in other branches
- 10.3.x modules/custom/social_graphql/src/Plugin/GraphQL/DataProducer/Field/Field.php \Drupal\social_graphql\Plugin\GraphQL\DataProducer\Field\Field::resolve()
 - 10.0.x modules/custom/social_graphql/src/Plugin/GraphQL/DataProducer/Field/Field.php \Drupal\social_graphql\Plugin\GraphQL\DataProducer\Field\Field::resolve()
 - 10.2.x modules/custom/social_graphql/src/Plugin/GraphQL/DataProducer/Field/Field.php \Drupal\social_graphql\Plugin\GraphQL\DataProducer\Field\Field::resolve()
 
Finds the requested field on the entity.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity that contains the field.
string $field: The name of the field to return.
Return value
\Drupal\Core\Field\FieldItemListInterface|null A field item list if the field exists or null if the entity is not fieldable or doesn't have the requested field.
File
- modules/
custom/ social_graphql/ src/ Plugin/ GraphQL/ DataProducer/ Field/ Field.php, line 48  
Class
- Field
 - Produces a field instance from an entity.
 
Namespace
Drupal\social_graphql\Plugin\GraphQL\DataProducer\FieldCode
public function resolve(EntityInterface $entity, string $field) : ?FieldItemListInterface {
  if (!$entity instanceof FieldableEntityInterface || !$entity
    ->hasField($field)) {
    return NULL;
  }
  $value = $entity
    ->get($field);
  // A FieldableEntityInterface::get will always return a
  // FieldItemListInterface which implements AccessibleInterface. Thus no
  // further typechecking is needed.
  return $value
    ->access('view') ? $value : NULL;
}