-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathDeleteEntity.php
More file actions
46 lines (40 loc) · 1.13 KB
/
DeleteEntity.php
File metadata and controls
46 lines (40 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Drupal\graphql\Plugin\GraphQL\DataProducer\Entity;
use Drupal\Core\Access\AccessResultReasonInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;
/**
* Deletes an entity.
*
* @DataProducer(
* id = "delete_entity",
* name = @Translation("Delete Entity"),
* produces = @ContextDefinition("entities",
* label = @Translation("Entities")
* ),
* consumes = {
* "entity" = @ContextDefinition("entity",
* label = @Translation("Entity")
* ),
* }
* )
*/
class DeleteEntity extends DataProducerPluginBase {
/**
* Resolve the values for this producer.
*/
public function resolve(ContentEntityInterface $entity, $context) {
$access = $entity->access('delete', NULL, TRUE);
$context->addCacheableDependency($access);
if (!$access->isAllowed()) {
return [
'was_successful' => FALSE,
'errors' => [$access instanceof AccessResultReasonInterface ? $access->getReason() : 'Access was forbidden.'],
];
}
$entity->delete();
return [
'was_successful' => TRUE,
];
}
}