You are here

final class FeaturedNodes in JSON:API Resources 8

Processes a request for a collection of featured nodes.

@internal

Hierarchy

Expanded class hierarchy of FeaturedNodes

1 string reference to 'FeaturedNodes'
jsonapi_resources_test.routing.yml in tests/modules/jsonapi_resources_test/jsonapi_resources_test.routing.yml
tests/modules/jsonapi_resources_test/jsonapi_resources_test.routing.yml

File

tests/modules/jsonapi_resources_test/src/Resource/FeaturedNodes.php, line 17

Namespace

Drupal\jsonapi_resources_test\Resource
View source
final class FeaturedNodes extends EntityQueryResourceBase {

  /**
   * Process the resource request.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The request.
   *
   * @return \Drupal\jsonapi\ResourceResponse
   *   The response.
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   */
  public function process(Request $request) : ResourceResponse {
    $query = $this
      ->getEntityQuery('node')
      ->condition('status', NodeInterface::PUBLISHED)
      ->condition('promote', NodeInterface::PROMOTED);
    $cacheability = new CacheableMetadata();
    $paginator = $this
      ->getPaginatorForRequest($request);
    $paginator
      ->applyToQuery($query, $cacheability);
    $data = $this
      ->loadResourceObjectDataFromEntityQuery($query, $cacheability);
    $pagination_links = $paginator
      ->getPaginationLinks($query, $cacheability);
    return $this
      ->createJsonapiResponse($data, $request, 200, [], $pagination_links);
  }

  /**
   * {@inheritdoc}
   */
  public function getRouteResourceTypes(Route $route, string $route_name) : array {
    return $this
      ->getResourceTypesByEntityTypeId('node');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityCreationTrait::modifyCreatedEntity protected function Modifies the created entity before it is saved. 2
EntityCreationTrait::processEntityCreation protected function Process the resource request.
EntityQueryResourceBase::$entityQueryExecutor private property The entity query executor utility.
EntityQueryResourceBase::getEntityQuery protected function Gets an entity query for the given entity type.
EntityQueryResourceBase::getPaginatorForRequest protected function Gets an entity query paginator for the current request.
EntityQueryResourceBase::loadResourceObjectDataFromEntityQuery protected function Finds entity resource object using an entity query.
EntityQueryResourceBase::loadResourceObjectsByEntityIds private function Loads and access checks entities loaded by ID as JSON:API resource objects.
EntityQueryResourceBase::setCacheabilityCapturingExecutor public function Sets the cacheability capturing entity query executor.
EntityResourceBase::$entityAccessChecker private property The JSON:API entity access checker.
EntityResourceBase::$entityTypeManager protected property The entity type manager.
EntityResourceBase::createCollectionDataFromEntities protected function Creates a JSON:API resource object from the given entity.
EntityResourceBase::createIndividualDataFromEntity protected function Creates a JSON:API resource object from the given entity.
EntityResourceBase::getResourceTypesByEntityTypeId protected function Get all resource types that represent variants of the given entity type ID.
EntityResourceBase::setEntityAccessChecker public function Sets the entity access checker.
EntityResourceBase::setEntityTypeManager public function Sets the entity type manager.
EntityValidationTrait::validate protected static function Verifies that an entity does not violate any validation constraints.
FeaturedNodes::getRouteResourceTypes public function Overrides ResourceBase::getRouteResourceTypes
FeaturedNodes::process public function Process the resource request.
ResourceBase::$documentExtractor private property The document extractor.
ResourceBase::$resourceResponseFactory private property The resource response factory.
ResourceBase::$resourceTypeRepository protected property The resource type repository.
ResourceBase::createJsonapiResponse protected function Builds a response with the appropriate wrapped document.
ResourceBase::getDocumentFromRequest protected function Get the document from the request.
ResourceBase::setDocumentExtractor public function Sets the document extractor.
ResourceBase::setResourceResponseFactory public function Sets the resource response factory.
ResourceBase::setResourceTypeRepository public function Sets the resource type repository.
ResourceObjectToEntityMapperAwareTrait::$resourceObjectToEntityMapper private property The service which created an entity from a resource object.
ResourceObjectToEntityMapperAwareTrait::setResourceObjectToEntityMapper public function