getIncludes example


        ],
      ],
    ]);
    if ($data instanceof ErrorCollection) {
      $document['errors'] = $this->normalizeErrorDocument($object$format$context);
    }
    else {
      // Add data.       $document['data'] = $this->serializer->normalize($data$format$context);
      // Add includes.       $document['included'] = $this->serializer->normalize($object->getIncludes()$format$context)->omitIfEmpty();
      // Add omissions and metadata.       $normalized_omissions = $this->normalizeOmissionsLinks($object->getOmissions()$format$context);
      $meta = !$normalized_omissions instanceof CacheableOmission
        ? array_merge($object->getMeta()['omitted' => $normalized_omissions->getNormalization()])
        : $object->getMeta();
      $document['meta'] = (new CacheableNormalization($normalized_omissions$meta))->omitIfEmpty();
    }
    // Add document links.     $document['links'] = $this->serializer->normalize($object->getLinks()$format$context)->omitIfEmpty();
    // Every JSON:API document contains absolute URLs.     return CacheableNormalization::aggregate($document)->withCacheableDependency((new CacheableMetadata())->addCacheContexts(['url.site']));
  }

  public function getIndividual(EntityInterface $entity, Request $request) {
    $resource_object = $this->entityAccessChecker->getAccessCheckedResourceObject($entity);
    if ($resource_object instanceof EntityAccessDeniedHttpException) {
      throw $resource_object;
    }
    $primary_data = new ResourceObjectData([$resource_object], 1);
    $response = $this->buildWrappedResponse($primary_data$request$this->getIncludes($request$primary_data));
    return $response;
  }

  /** * Creates an individual entity. * * @param \Drupal\jsonapi\ResourceType\ResourceType $resource_type * The JSON:API resource type for the request to be served. * @param \Symfony\Component\HttpFoundation\Request $request * The request object. * * @return \Drupal\jsonapi\ResourceResponse * The response. * * @throws \Symfony\Component\HttpKernel\Exception\ConflictHttpException * Thrown when the entity already exists. * @throws \Drupal\jsonapi\Exception\UnprocessableHttpEntityException * Thrown when the entity does not pass validation. */
$decoded[] = $this->getDecodedEntity($criteria$entity$definition$baseUrl);
        }

        return $decoded;
    }

    private function getDecodedEntity(Criteria $criteria, Entity $entity, EntityDefinition $definition, string $baseUrl): array
    {
        /** @var array<mixed> $decoded */
        $decoded = $this->serializer->normalize($entity);

        $includes = $criteria->getIncludes() ?? [];
        $decoded = $this->filterIncludes($includes$decoded$entity);

        if (isset($decoded['customFields']) && $decoded['customFields'] === []) {
            $decoded['customFields'] = new \stdClass();
        }

        if (isset($decoded['translated']['customFields']) && $decoded['translated']['customFields'] === []) {
            $decoded['translated']['customFields'] = new \stdClass();
        }

        return $this->removeNotAllowedFields($decoded$definition$baseUrl);
    }

        $this->serializeCache = [];
        $result = new JsonApiEncodingResult($baseUrl);

        if (!$data instanceof EntityCollection && !$data instanceof Entity) {
            throw new UnsupportedEncoderInputException();
        }

        $result->setSingleResult($data instanceof Entity);
        $result->setMetaData($metaData);

        $fields = new ResponseFields($criteria->getIncludes());

        $this->encodeData($fields$definition$data$result);

        return $this->formatToJson($result);
    }

    protected function serializeEntity(ResponseFields $fields, Entity $entity, EntityDefinition $definition, JsonApiEncodingResult $result, bool $isRelationship = false): void
    {
        if ($result->containsInData($entity->getUniqueIdentifier()$definition->getEntityName())
            || ($isRelationship && $result->containsInIncluded($entity->getUniqueIdentifier()$definition->getEntityName()))
        ) {
            
public function exists(string $name)
    {
        return $this->get($name) !== null;
    }

    private function get(string $name): ?Script
    {
        if ($this->script->getName() === $name) {
            return $this->script;
        }

        foreach ($this->script->getIncludes() as $include) {
            if ($include->getName() === $name) {
                return $include;
            }
        }

        return null;
    }
}
$array['limit'] = $criteria->getLimit();
        }

        if ($criteria->getOffset()) {
            $array['page'] = ($criteria->getOffset() / $criteria->getLimit()) + 1;
        }

        if ($criteria->getTerm()) {
            $array['term'] = $criteria->getTerm();
        }

        if ($criteria->getIncludes()) {
            $array['includes'] = $criteria->getIncludes();
        }

        if (\count($criteria->getIds())) {
            $array['ids'] = $criteria->getIds();
        }

        if (\count($criteria->getFilters())) {
            $array['filter'] = array_map(static fn (Filter $filter) => QueryStringParser::toArray($filter)$criteria->getFilters());
        }

        
Home | Imprint | This part of the site doesn't use cookies.