public function DeleteEntityBase::resolve in GraphQL 8.3
File
- modules/graphql_core/src/Plugin/GraphQL/Mutations/Entity/DeleteEntityBase.php, line 72
Class
- DeleteEntityBase
Namespace
Drupal\graphql_core\Plugin\GraphQL\Mutations\Entity
Code
public function resolve($value, array $args, ResolveContext $context, ResolveInfo $info) {
return $this->renderer
->executeInRenderContext(new RenderContext(), function () use ($value, $args, $context, $info) {
$entityTypeId = $this->pluginDefinition['entity_type'];
$storage = $this->entityTypeManager
->getStorage($entityTypeId);
if (!($entity = $storage
->load($args['id']))) {
return new EntityCrudOutputWrapper(NULL, NULL, [
$this
->t('The requested entity could not be loaded.'),
]);
}
if (!$entity
->access('delete')) {
return new EntityCrudOutputWrapper(NULL, NULL, [
$this
->t('You do not have the necessary permissions to delete this entity.'),
]);
}
try {
$entity
->delete();
} catch (EntityStorageException $exception) {
return new EntityCrudOutputWrapper(NULL, NULL, [
$this
->t('Entity deletion failed with exception: @exception.', [
'@exception' => $exception
->getMessage(),
]),
]);
}
return new EntityCrudOutputWrapper($entity);
});
}