toResourceIdentifier example

protected function doTestRelationshipMutation(array $request_options) {
    /** @var \Drupal\Core\Entity\FieldableEntityInterface $resource */
    $resource = $this->createAnotherEntity('dupe');
    $resource->set('field_jsonapi_test_entity_ref', NULL);
    $violations = $resource->validate();
    assert($violations->count() === 0, (string) $violations);
    $resource->save();
    $target_resource = $this->createUser();
    $violations = $target_resource->validate();
    assert($violations->count() === 0, (string) $violations);
    $target_resource->save();
    $target_identifier = static::toResourceIdentifier($target_resource);
    $resource_identifier = static::toResourceIdentifier($resource);
    $relationship_field_name = 'field_jsonapi_test_entity_ref';
    /** @var \Drupal\Core\Access\AccessResultReasonInterface $update_access */
    $update_access = static::entityAccess($resource, 'update', $this->account)
      ->andIf(static::entityFieldAccess($resource$relationship_field_name, 'edit', $this->account));
    $url = Url::fromRoute(sprintf("jsonapi.{$resource_identifier['type']}.{$relationship_field_name}.relationship.patch")[
      'entity' => $resource->uuid(),
    ]);

    // Test POST: missing content-type.     $response = $this->request('POST', $url$request_options);
    

  public static function toResourceIdentifiers(EntityReferenceFieldItemListInterface $items) {
    $relationships = [];
    foreach ($items->filterEmptyItems() as $item) {
      // Create a ResourceIdentifier from the field item. This will make it       // comparable with all previous field items. Here, it is assumed that the       // resource identifier is unique so it has no arity. If a parallel       // relationship is encountered, it will be assigned later.       $relationship = static::toResourceIdentifier($item);
      if ($relationship->getResourceType()->isInternal()) {
        continue;
      }
      // Now, iterate over the previously seen resource identifiers in reverse       // order. Reverse order is important so that when a parallel relationship       // is encountered, it will have the highest arity value so the current       // relationship's arity value can simply be incremented by one.       /** @var \Drupal\jsonapi\JsonApiResource\ResourceIdentifier $existing */
      foreach (array_reverse($relationships, TRUE) as $index => $existing) {
        $is_parallel = static::isParallel($existing$relationship);
        if ($is_parallel) {
          
'entity' => $entity->uuid()]
          );
          $collected_responses[] = static::getAccessDeniedResponse($entity$field_access$via_link$field_name, 'The current user is not allowed to view this relationship.', $field_name);
          break;
        }
        if ($target_entity = $entity->{$field_name}->entity) {
          $target_access = static::entityAccess($target_entity, 'view', $this->account);
          if (!$target_access->isAllowed()) {
            $target_access = static::entityAccess($target_entity, 'view label', $this->account)->addCacheableDependency($target_access);
          }
          if (!$target_access->isAllowed()) {
            $resource_identifier = static::toResourceIdentifier($target_entity);
            if (!static::collectionHasResourceIdentifier($resource_identifier$data['already_checked'])) {
              $data['already_checked'][] = $resource_identifier;
              $via_link = Url::fromRoute(
                sprintf('jsonapi.%s.individual', $resource_identifier['type']),
                ['entity' => $resource_identifier['id']]
              );
              $collected_responses[] = static::getAccessDeniedResponse($entity$target_access$via_link, NULL, NULL, '/data');
            }
            break;
          }
        }
        
Home | Imprint | This part of the site doesn't use cookies.