final class AddReminder in JSON:API Resources 8
Processes a request to create a reminder node for a user.
@package Drupal\jsonapi_resources_test\Resource
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\AddReminder implements ContainerInjectionInterface
- class \Drupal\jsonapi_resources\Resource\EntityQueryResourceBase
- class \Drupal\jsonapi_resources\Resource\EntityResourceBase implements ResourceObjectToEntityMapperAwareInterface uses EntityCreationTrait
Expanded class hierarchy of AddReminder
1 string reference to 'AddReminder'
- 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/ AddReminder.php, line 22
Namespace
Drupal\jsonapi_resources_test\ResourceView source
final class AddReminder extends EntityQueryResourceBase implements ContainerInjectionInterface {
/**
* The current user account.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* Constructs a resource for adding a reminder.
*
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user account.
*/
public function __construct(AccountInterface $current_user) {
$this->currentUser = $current_user;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('current_user'));
}
/**
* Process the resource request.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request.
* @param \Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel $document
* The deserialized request document.
*
* @return \Drupal\jsonapi\ResourceResponse
* The response.
*
* @throws \Symfony\Component\HttpKernel\Exception\ConflictHttpException
* Thrown when the entity to be created already exists.
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* Thrown if the storage handler couldn't be loaded.
* @throws \Drupal\Core\Entity\EntityStorageException
* Thrown if the entity could not be saved.
*/
public function process(Request $request, JsonApiDocumentTopLevel $document) : ResourceResponse {
return $this
->processEntityCreation($request, $document);
}
/**
* {@inheritdoc}
*/
protected function modifyCreatedEntity(EntityInterface $created_entity, Request $request) {
assert($created_entity instanceof NodeInterface);
$created_entity
->setOwnerId($this->currentUser
->id());
}
/**
* Performs custom access checks for the route.
*
* @param \Drupal\user\UserInterface $user
* The user from the route.
*
* @return \Drupal\Core\Access\AccessResult
* Allowed if the currently authenticated user is the same as the user
* loaded via a route parameter, FALSE otherwise.
*/
public function access(UserInterface $user) {
return AccessResult::allowedIf($user
->id() === $this->currentUser
->id())
->cachePerUser();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AddReminder:: |
protected | property | The current user account. | |
AddReminder:: |
public | function | Performs custom access checks for the route. | |
AddReminder:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
AddReminder:: |
protected | function |
Modifies the created entity before it is saved. Overrides EntityCreationTrait:: |
|
AddReminder:: |
public | function | Process the resource request. | |
AddReminder:: |
public | function | Constructs a resource for adding a reminder. | |
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 |