getRelatedLink example

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;
          }
        }
        $psr_responses = $this->getResponses([static::getRelatedLink(static::toResourceIdentifier($entity)$public_field_name)]$request_options);
        $collected_responses[] = static::toCollectionResourceResponse(static::toResourceResponses($psr_responses), NULL, TRUE);
        $entity = $entity->{$field_name}->entity;
      }
      if (!empty($collected_responses)) {
        $data['responses'][$path] = static::toCollectionResourceResponse($collected_responses, NULL, TRUE);
      }
      return $data;
    }['responses' => [], 'already_checked' => []]);

    $individual_document = $this->getExpectedDocument();

    
$detail = 'The current user is not allowed to view this relationship.';
      if (!$entity->access('view') && $entity->access('view label') && $access instanceof AccessResultReasonInterface && empty($access->getReason())) {
        $access->setReason("The user only has authorization for the 'view label' operation.");
      }
      $via_link = Url::fromRoute(
        sprintf('jsonapi.%s.%s.related', $base_resource_identifier['type']$relationship_field_name),
        ['entity' => $base_resource_identifier['id']]
      );
      $related_response = static::getAccessDeniedResponse($entity$access$via_link$relationship_field_name$detail, FALSE);
    }
    else {
      $self_link = static::getRelatedLink($base_resource_identifier$relationship_field_name);
      $relationship_response = $this->getExpectedGetRelationshipResponse($relationship_field_name$entity);
      $relationship_document = $relationship_response->getResponseData();
      // The relationships may be empty, in which case we shouldn't attempt to       // fetch the individual identified resources.       if (empty($relationship_document['data'])) {
        $cache_contexts = Cache::mergeContexts([
          // Cache contexts for JSON:API URL query parameters.           'url.query_args:fields',
          'url.query_args:include',
          // Drupal defaults.           'url.site',
        ],
Home | Imprint | This part of the site doesn't use cookies.