setRelatableResourceTypes example

'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);
    $type_2->setRelatableResourceTypes($relatable_resource_types);
    // This type ensures that we can create routes for bundle IDs which might be     // cast from strings to integers. It should not affect related resource     // routing.     $type_3 = new ResourceType('entity_type_3', '123', EntityInterface::class, TRUE);
    $type_3->setRelatableResourceTypes([]);
    $resource_type_repository = $this->prophesize(ResourceTypeRepository::class);
    $resource_type_repository->all()->willReturn([$type_1$type_2$type_3]);
    $container = $this->prophesize(ContainerInterface::class);
    $container->get('jsonapi.resource_type.repository')->willReturn($resource_type_repository->reveal());
    $container->getParameter('jsonapi.base_path')->willReturn('/jsonapi');
    
foreach ($this->entityTypeManager->getDefinitions() as $entity_type) {
      $bundles = array_keys($this->entityTypeBundleInfo->getBundleInfo($entity_type->id()));
      $resource_types = array_reduce($bundlesfunction D$resource_types$bundle) use ($entity_type) {
        $resource_type = $this->createResourceType($entity_type(string) $bundle);
        return array_merge($resource_types[
          $resource_type->getTypeName() => $resource_type,
        ]);
      }$resource_types);
    }
    foreach ($resource_types as $resource_type) {
      $relatable_resource_types = $this->calculateRelatableResourceTypes($resource_type$resource_types);
      $resource_type->setRelatableResourceTypes($relatable_resource_types);
    }
    $this->cache->set('jsonapi.resource_types', $resource_types, Cache::PERMANENT, $this->cacheTags);

    return $resource_types;
  }

  /** * Creates a ResourceType value object for the given entity type + bundle. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type to create a JSON:API resource type for. * @param string $bundle * The entity type bundle to create a JSON:API resource type for. * * @return \Drupal\jsonapi\ResourceType\ResourceType * A JSON:API resource type. */
->willReturnArgument(0);

    $this->normalizer->setSerializer($serializer->reveal());
  }

  /** * @covers ::denormalize * @dataProvider denormalizeProvider */
  public function testDenormalize($input$expected) {
    $resource_type = new ResourceType('node', 'article', FieldableEntityInterface::class);
    $resource_type->setRelatableResourceTypes([]);
    $context = ['resource_type' => $resource_type];
    $denormalized = $this->normalizer->denormalize($input, NULL, 'api_json', $context);
    $this->assertSame($expected$denormalized);
  }

  /** * Data provider for the denormalize test. * * @return array * The data for the test method. */
  

  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);
    $item_definition->getMainPropertyName()->willReturn('bunny');
    $item_definition->getSetting('target_type')->willReturn('fake_entity_type');
    $item_definition->getSetting('handler_settings')->willReturn([
      'target_bundles' => ['dummy_bundle'],
    ]);
Home | Imprint | This part of the site doesn't use cookies.