You are here

protected function ListDataDefinitionNormalizer::isReferenceField in JSON:API Schema 8

Determine if the current field is a reference field.

Parameters

\Drupal\Core\TypedData\ListDataDefinitionInterface $entity: The list definition to be checked.

Return value

bool TRUE if it is a reference, FALSE otherwise.

File

src/Normalizer/ListDataDefinitionNormalizer.php, line 82

Class

ListDataDefinitionNormalizer
Normalizer for ListDataDefinitionInterface objects.

Namespace

Drupal\jsonapi_schema\Normalizer

Code

protected function isReferenceField(ListDataDefinitionInterface $entity) {
  $item = $entity
    ->getItemDefinition();
  if ($item instanceof ComplexDataDefinitionInterface) {
    $main = $item
      ->getPropertyDefinition($item
      ->getMainPropertyName());

    // @todo use an interface or API call instead of an object check.
    return $main instanceof DataReferenceTargetDefinition;
  }
  return FALSE;
}