protected function AddComment::modifyCreatedEntity in JSON:API Resources 8
Modifies the created entity before it is saved.
This method can be overridden so that custom JSON:API resources can modify the created entity before it is saved.
Classes overriding this method have access to the same arguments as a JSON:API resource's process() method by calling $request->arguments->get($arg_name).
Parameters
\Drupal\Core\Entity\EntityInterface $created_entity: The created entity.
\Symfony\Component\HttpFoundation\Request $request: The request object.
Overrides EntityCreationTrait::modifyCreatedEntity
File
- tests/
modules/ jsonapi_resources_test/ src/ Resource/ AddComment.php, line 73
Class
- AddComment
- Processes a request to create a comment on an article.
Namespace
Drupal\jsonapi_resources_test\ResourceCode
protected function modifyCreatedEntity(EntityInterface $created_entity, Request $request) {
assert($created_entity instanceof CommentInterface);
$created_entity
->setOwnerId($this->currentUser
->id());
}