class JsonApiDocumentTopLevel

Same name in other branches
  1. 9 core/modules/jsonapi/src/JsonApiResource/JsonApiDocumentTopLevel.php \Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel
  2. 8.9.x core/modules/jsonapi/src/JsonApiResource/JsonApiDocumentTopLevel.php \Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel
  3. 10 core/modules/jsonapi/src/JsonApiResource/JsonApiDocumentTopLevel.php \Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel

Represents a JSON:API document's "top level".

@internal JSON:API maintains no PHP API. The API is the HTTP API. This class may change at any time and could break any dependencies on it.

@todo Add support for the missing optional 'jsonapi' member or document why not.

Hierarchy

Expanded class hierarchy of JsonApiDocumentTopLevel

See also

https://www.drupal.org/project/drupal/issues/3032787

jsonapi.api.php

http://jsonapi.org/format/#document-top-level

9 files declare their use of JsonApiDocumentTopLevel
DefaultExceptionSubscriber.php in core/modules/jsonapi/src/EventSubscriber/DefaultExceptionSubscriber.php
EntityResource.php in core/modules/jsonapi/src/Controller/EntityResource.php
EntityResourceTest.php in core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php
EntryPoint.php in core/modules/jsonapi/src/Controller/EntryPoint.php
FileUpload.php in core/modules/jsonapi/src/Controller/FileUpload.php

... See full list

File

core/modules/jsonapi/src/JsonApiResource/JsonApiDocumentTopLevel.php, line 18

Namespace

Drupal\jsonapi\JsonApiResource
View source
class JsonApiDocumentTopLevel {
    
    /**
     * The data to normalize.
     *
     * @var \Drupal\jsonapi\JsonApiResource\ResourceIdentifierInterface|\Drupal\jsonapi\JsonApiResource\Data|\Drupal\jsonapi\JsonApiResource\ErrorCollection|\Drupal\Core\Field\EntityReferenceFieldItemListInterface
     */
    protected $data;
    
    /**
     * The metadata to normalize.
     *
     * @var array
     */
    protected $meta;
    
    /**
     * The links.
     *
     * @var \Drupal\jsonapi\JsonApiResource\LinkCollection
     */
    protected $links;
    
    /**
     * The includes to normalize.
     *
     * @var \Drupal\jsonapi\JsonApiResource\IncludedData
     */
    protected $includes;
    
    /**
     * Resource objects that will be omitted from the response for access reasons.
     *
     * @var \Drupal\jsonapi\JsonApiResource\OmittedData
     */
    protected $omissions;
    
    /**
     * Instantiates a JsonApiDocumentTopLevel object.
     *
     * @param \Drupal\jsonapi\JsonApiResource\TopLevelDataInterface|\Drupal\jsonapi\JsonApiResource\ErrorCollection $data
     *   The data to normalize. It can be either a ResourceObject, or a stand-in
     *   for one, or a collection of the same.
     * @param \Drupal\jsonapi\JsonApiResource\IncludedData $includes
     *   A JSON:API Data object containing resources to be included in the
     *   response document or NULL if there should not be includes.
     * @param \Drupal\jsonapi\JsonApiResource\LinkCollection $links
     *   A collection of links to resources related to the top-level document.
     * @param array $meta
     *   (optional) The metadata to normalize.
     */
    public function __construct($data, IncludedData $includes, LinkCollection $links, array $meta = []) {
        assert($data instanceof TopLevelDataInterface || $data instanceof ErrorCollection);
        assert(!$data instanceof ErrorCollection || $includes instanceof NullIncludedData);
        $this->data = $data instanceof TopLevelDataInterface ? $data->getData() : $data;
        $this->includes = $includes->getData();
        $this->links = $data instanceof TopLevelDataInterface ? $data->getMergedLinks($links->withContext($this)) : $links->withContext($this);
        $this->meta = $data instanceof TopLevelDataInterface ? $data->getMergedMeta($meta) : $meta;
        $this->omissions = $data instanceof TopLevelDataInterface ? OmittedData::merge($data->getOmissions(), $includes->getOmissions()) : $includes->getOmissions();
    }
    
    /**
     * Gets the data.
     *
     * @return \Drupal\jsonapi\JsonApiResource\Data|\Drupal\jsonapi\JsonApiResource\ErrorCollection
     *   The data.
     */
    public function getData() {
        return $this->data;
    }
    
    /**
     * Gets the links.
     *
     * @return \Drupal\jsonapi\JsonApiResource\LinkCollection
     *   The top-level links.
     */
    public function getLinks() {
        return $this->links;
    }
    
    /**
     * Gets the metadata.
     *
     * @return array
     *   The metadata.
     */
    public function getMeta() {
        return $this->meta;
    }
    
    /**
     * Gets a JSON:API Data object of resources to be included in the response.
     *
     * @return \Drupal\jsonapi\JsonApiResource\IncludedData
     *   The includes.
     */
    public function getIncludes() {
        return $this->includes;
    }
    
    /**
     * Gets an OmittedData instance containing resources to be omitted.
     *
     * @return \Drupal\jsonapi\JsonApiResource\OmittedData
     *   The omissions.
     */
    public function getOmissions() {
        return $this->omissions;
    }

}

Members

Title Sort descending Modifiers Object type Summary
JsonApiDocumentTopLevel::$data protected property The data to normalize.
JsonApiDocumentTopLevel::$includes protected property The includes to normalize.
JsonApiDocumentTopLevel::$links protected property The links.
JsonApiDocumentTopLevel::$meta protected property The metadata to normalize.
JsonApiDocumentTopLevel::$omissions protected property Resource objects that will be omitted from the response for access reasons.
JsonApiDocumentTopLevel::getData public function Gets the data.
JsonApiDocumentTopLevel::getIncludes public function Gets a JSON:API Data object of resources to be included in the response.
JsonApiDocumentTopLevel::getLinks public function Gets the links.
JsonApiDocumentTopLevel::getMeta public function Gets the metadata.
JsonApiDocumentTopLevel::getOmissions public function Gets an OmittedData instance containing resources to be omitted.
JsonApiDocumentTopLevel::__construct public function Instantiates a JsonApiDocumentTopLevel object.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.