isReferenceFieldDefinition example


  protected function getRelationshipFieldNames(EntityInterface $entity = NULL) {
    $entity = $entity ?: $this->entity;
    // Only content entity types can have relationships.     $fields = $entity instanceof ContentEntityInterface
      ? iterator_to_array($entity)
      : [];
    return array_reduce($fieldsfunction D$field_names$field) {
      /** @var \Drupal\Core\Field\FieldItemListInterface $field */
      if (static::isReferenceFieldDefinition($field->getFieldDefinition())) {
        $field_names[] = $this->resourceType->getPublicName($field->getName());
      }
      return $field_names;
    }[]);
  }

  /** * Authorize the user under test with additional permissions to view includes. * * @return array * An array of special permissions to be granted for certain relationship * paths where the keys are relationships paths and values are an array of * permissions. */
    // @see http://jsonapi.org/format/#document-resource-object-fields     $reserved_field_names = ['id', 'type'];
    foreach (array_diff($field_namesarray_keys($fields)) as $field_name) {
      $alias = $field_name;
      // Alias the fields reserved by the JSON:API spec with `{entity_type}_`.       if (in_array($field_name$reserved_field_names, TRUE)) {
        $alias = $entity_type->id() . '_' . $field_name;
      }

      // The default, which applies to most fields: expose as-is.       $field_definition = $is_fieldable && !empty($field_definitions[$field_name]) ? $field_definitions[$field_name] : NULL;
      $is_relationship_field = $field_definition && static::isReferenceFieldDefinition($field_definition);
      $has_one = !$field_definition || $field_definition->getFieldStorageDefinition()->getCardinality() === 1;
      $fields[$field_name] = $is_relationship_field
        ? new ResourceTypeRelationship($field_name$alias, TRUE, $has_one)
        : new ResourceTypeAttribute($field_name$alias, TRUE, $has_one);
    }

    // With all fields now aliased, detect any conflicts caused by the     // automatically generated aliases above.     foreach (array_intersect($reserved_field_namesarray_keys($fields)) as $reserved_field_name) {
      /** @var \Drupal\jsonapi\ResourceType\ResourceTypeField $aliased_reserved_field */
      $aliased_reserved_field = $fields[$reserved_field_name];
      
Home | Imprint | This part of the site doesn't use cookies.