ResourceTypeRelationship example

$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];
      /** @var \Drupal\jsonapi\ResourceType\ResourceTypeField $field */
      foreach (array_diff_key($fieldsarray_flip([$reserved_field_name])) as $field) {
        if ($aliased_reserved_field->getPublicName() === $field->getPublicName()) {
          

  protected $routes;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $relationship_fields = [
      'external' => new ResourceTypeRelationship('external'),
      'internal' => new ResourceTypeRelationship('internal'),
      'both' => new ResourceTypeRelationship('both'),
    ];
    $type_1 = new ResourceType('entity_type_1', 'bundle_1_1', EntityInterface::class, FALSE, TRUE, TRUE, FALSE, $relationship_fields);
    $type_2 = new ResourceType('entity_type_2', 'bundle_2_1', EntityInterface::class, TRUE, TRUE, TRUE, FALSE, $relationship_fields);
    $relatable_resource_types = [
      'external' => [$type_1],
      'internal' => [$type_2],
      'both' => [$type_1$type_2],
    ];
    $type_1->setRelatableResourceTypes($relatable_resource_types);
    

  protected $resourceType;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $target_resource_type = new ResourceType('lorem', 'dummy_bundle', NULL);
    $relationship_fields = [
      'field_dummy' => new ResourceTypeRelationship('field_dummy'),
      'field_dummy_single' => new ResourceTypeRelationship('field_dummy_single'),
    ];
    $this->resourceType = new ResourceType('fake_entity_type', 'dummy_bundle', NULL, FALSE, TRUE, TRUE, FALSE, $relationship_fields);
    $this->resourceType->setRelatableResourceTypes([
      'field_dummy' => [$target_resource_type],
      'field_dummy_single' => [$target_resource_type],
    ]);

    $field_manager = $this->prophesize(EntityFieldManagerInterface::class);
    $field_definition = $this->prophesize(FieldConfig::class);
    $item_definition = $this->prophesize(FieldItemDataDefinition::class);
    
Home | Imprint | This part of the site doesn't use cookies.