class AuthorArticles in JSON:API Resources 8
Processes a request for a collection containing a user's article nodes.
@internal
Hierarchy
- class \Drupal\jsonapi_resources\Resource\ResourceBase
- class \Drupal\jsonapi_resources\Resource\EntityResourceBase implements ResourceObjectToEntityMapperAwareInterface uses EntityCreationTrait
- class \Drupal\jsonapi_resources\Resource\EntityQueryResourceBase
- class \Drupal\jsonapi_resources_test\Resource\AuthorArticles
- class \Drupal\jsonapi_resources\Resource\EntityQueryResourceBase
- class \Drupal\jsonapi_resources\Resource\EntityResourceBase implements ResourceObjectToEntityMapperAwareInterface uses EntityCreationTrait
Expanded class hierarchy of AuthorArticles
1 string reference to 'AuthorArticles'
- 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/ AuthorArticles.php, line 17
Namespace
Drupal\jsonapi_resources_test\ResourceView source
class AuthorArticles extends EntityQueryResourceBase {
/**
* Process the resource request.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request.
* @param \Drupal\user\UserInterface $user
* The user.
*
* @return \Drupal\jsonapi\ResourceResponse
* The response.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function process(Request $request, UserInterface $user) : ResourceResponse {
// Force the author to be included.
$include = $request->query
->get('include');
$request->query
->set('include', $include . (empty($include) ? '' : ',') . 'uid');
$cacheability = new CacheableMetadata();
$entity_type = $this->entityTypeManager
->getDefinition('node');
$entity_query = $this
->getEntityQuery('node')
->condition($entity_type
->getKey('bundle'), 'article')
->condition($entity_type
->getKey('status'), NodeInterface::PUBLISHED)
->condition($entity_type
->getKey('uid'), $user
->id());
$cacheability
->addCacheContexts([
'url.path',
]);
$paginator = $this
->getPaginatorForRequest($request);
$paginator
->applyToQuery($entity_query, $cacheability);
$data = $this
->loadResourceObjectDataFromEntityQuery($entity_query, $cacheability);
$pagination_links = $paginator
->getPaginationLinks($entity_query, $cacheability, TRUE);
$response = $this
->createJsonapiResponse($data, $request, 200, [], $pagination_links);
$response
->addCacheableDependency($cacheability);
return $response;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AuthorArticles:: |
public | function | Process the resource request. | |
EntityCreationTrait:: |
protected | function | Modifies the created entity before it is saved. | 2 |
EntityCreationTrait:: |
protected | function | Process the resource request. | |
EntityQueryResourceBase:: |
private | property | The entity query executor utility. | |
EntityQueryResourceBase:: |
protected | function | Gets an entity query for the given entity type. | |
EntityQueryResourceBase:: |
protected | function | Gets an entity query paginator for the current request. | |
EntityQueryResourceBase:: |
protected | function | Finds entity resource object using an entity query. | |
EntityQueryResourceBase:: |
private | function | Loads and access checks entities loaded by ID as JSON:API resource objects. | |
EntityQueryResourceBase:: |
public | function | Sets the cacheability capturing entity query executor. | |
EntityResourceBase:: |
private | property | The JSON:API entity access checker. | |
EntityResourceBase:: |
protected | property | The entity type manager. | |
EntityResourceBase:: |
protected | function | Creates a JSON:API resource object from the given entity. | |
EntityResourceBase:: |
protected | function | Creates a JSON:API resource object from the given entity. | |
EntityResourceBase:: |
protected | function | Get all resource types that represent variants of the given entity type ID. | |
EntityResourceBase:: |
public | function | Sets the entity access checker. | |
EntityResourceBase:: |
public | function | Sets the entity type manager. | |
EntityValidationTrait:: |
protected static | function | Verifies that an entity does not violate any validation constraints. | |
ResourceBase:: |
private | property | The document extractor. | |
ResourceBase:: |
private | property | The resource response factory. | |
ResourceBase:: |
protected | property | The resource type repository. | |
ResourceBase:: |
protected | function | Builds a response with the appropriate wrapped document. | |
ResourceBase:: |
protected | function | Get the document from the request. | |
ResourceBase:: |
public | function | 2 | |
ResourceBase:: |
public | function | Sets the document extractor. | |
ResourceBase:: |
public | function | Sets the resource response factory. | |
ResourceBase:: |
public | function | Sets the resource type repository. | |
ResourceObjectToEntityMapperAwareTrait:: |
private | property | The service which created an entity from a resource object. | |
ResourceObjectToEntityMapperAwareTrait:: |
public | function |