1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DNADesign\Elemental\GraphQL; |
4
|
|
|
|
5
|
|
|
use DNADesign\Elemental\Models\BaseElement; |
6
|
|
|
use DNADesign\Elemental\Models\ElementalArea; |
7
|
|
|
use DNADesign\Elemental\Services\ReorderElements; |
8
|
|
|
use GraphQL\Type\Definition\ResolveInfo; |
|
|
|
|
9
|
|
|
use GraphQL\Type\Definition\Type; |
|
|
|
|
10
|
|
|
use InvalidArgumentException; |
11
|
|
|
use SilverStripe\Core\Injector\Injector; |
12
|
|
|
use SilverStripe\GraphQL\MutationCreator; |
|
|
|
|
13
|
|
|
use SilverStripe\GraphQL\OperationResolver; |
|
|
|
|
14
|
|
|
|
15
|
|
|
class AddElementToAreaMutation extends MutationCreator implements OperationResolver |
16
|
|
|
{ |
17
|
|
|
public function attributes() |
18
|
|
|
{ |
19
|
|
|
return [ |
20
|
|
|
'name' => 'addElementToArea', |
21
|
|
|
'description' => 'Adds an Element to an ElementalArea, optionally after another Element' |
22
|
|
|
]; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function type() |
26
|
|
|
{ |
27
|
|
|
return $this->manager->getType('Block'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function args() |
31
|
|
|
{ |
32
|
|
|
return [ |
33
|
|
|
'ClassName' => ['type' => Type::nonNull(Type::string())], |
34
|
|
|
'ElementalAreaID' => ['type' => Type::nonNull(Type::id())], |
35
|
|
|
'AfterElementID' => ['type' => Type::id()], |
36
|
|
|
]; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function resolve($object, array $args, $context, ResolveInfo $info) |
40
|
|
|
{ |
41
|
|
|
$elementClass = $args['ClassName']; |
42
|
|
|
$elementalAreaID = $args['ElementalAreaID']; |
43
|
|
|
$afterElementID = isset($args['AfterElementID']) ? $args['AfterElementID'] : null; |
44
|
|
|
|
45
|
|
|
if (!is_subclass_of($elementClass, BaseElement::class)) { |
46
|
|
|
throw new InvalidArgumentException("$elementClass is not a subclass of " . BaseElement::class); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$elementalArea = ElementalArea::get()->byID($elementalAreaID); |
50
|
|
|
|
51
|
|
|
if (!$elementalArea) { |
|
|
|
|
52
|
|
|
throw new InvalidArgumentException("Invalid ElementalAreaID: $elementalAreaID"); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if (!$elementalArea->canEdit($context['currentUser'])) { |
56
|
|
|
throw new InvalidArgumentException("The current user has insufficient permission to edit ElementalAreas"); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$newElement = Injector::inst()->create($elementClass); |
60
|
|
|
|
61
|
|
|
if (!$newElement->canEdit($context['currentUser'])) { |
62
|
|
|
throw new InvalidArgumentException( |
63
|
|
|
'The current user has insufficient permission to edit Elements' |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$elementalArea->Elements()->add($newElement); |
68
|
|
|
|
69
|
|
|
if (!is_null($afterElementID)) { |
70
|
|
|
$reorderer = Injector::inst()->create(ReorderElements::class, $newElement); |
71
|
|
|
$reorderer->reorder($afterElementID); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $newElement; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths