1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LAG\AdminBundle\EventListener\Operation; |
6
|
|
|
|
7
|
|
|
use LAG\AdminBundle\Event\Events\OperationCreateEvent; |
8
|
|
|
use LAG\AdminBundle\Form\Type\OperationDataType; |
9
|
|
|
use LAG\AdminBundle\Form\Type\ResourceFilterType; |
10
|
|
|
use LAG\AdminBundle\Metadata\Action; |
|
|
|
|
11
|
|
|
use LAG\AdminBundle\Metadata\CollectionOperationInterface; |
12
|
|
|
use LAG\AdminBundle\Metadata\Create; |
13
|
|
|
use LAG\AdminBundle\Metadata\Index; |
14
|
|
|
use LAG\AdminBundle\Metadata\Update; |
15
|
|
|
use LAG\AdminBundle\Routing\Route\RouteNameGeneratorInterface; |
16
|
|
|
|
17
|
|
|
class CreateListener |
18
|
|
|
{ |
19
|
|
|
public function __construct( |
20
|
|
|
private RouteNameGeneratorInterface $routeNameGenerator, |
21
|
|
|
) { |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function __invoke(OperationCreateEvent $event): void |
25
|
|
|
{ |
26
|
|
|
$operation = $event->getOperation(); |
27
|
|
|
$resource = $operation->getResource(); |
28
|
|
|
|
29
|
|
|
if (!$operation->getItemActions()) { |
30
|
|
|
$actions = []; |
31
|
|
|
|
32
|
|
|
if ($operation instanceof CollectionOperationInterface) { |
33
|
|
|
if ($resource->hasOperation('update')) { |
34
|
|
|
$actions[] = new Action( |
35
|
|
|
resourceName: $resource->getName(), |
36
|
|
|
operationName: 'update', |
37
|
|
|
label: 'lag_admin.resource.update', |
38
|
|
|
type: 'secondary' |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if ($resource->hasOperation('delete')) { |
43
|
|
|
$actions[] = new Action( |
44
|
|
|
resourceName: $resource->getName(), |
45
|
|
|
operationName: 'delete', |
46
|
|
|
label: 'lag_admin.resource.delete', |
47
|
|
|
type: 'danger' |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
} else { |
51
|
|
|
if ($resource->hasOperation('index')) { |
52
|
|
|
$actions[] = new Action( |
53
|
|
|
resourceName: $resource->getName(), |
54
|
|
|
operationName: 'index', |
55
|
|
|
label: 'lag_admin.ui.cancel', |
56
|
|
|
type: 'light', |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
$operation = $operation->withItemActions($actions); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if ($operation instanceof CollectionOperationInterface && !$operation->getListActions()) { |
|
|
|
|
64
|
|
|
if ($resource->hasOperation('create')) { |
65
|
|
|
$operation = $operation->withListActions([new Action( |
|
|
|
|
66
|
|
|
resourceName: $resource->getName(), |
67
|
|
|
operationName: 'create', |
68
|
|
|
label: 'lag_admin.ui.create', |
69
|
|
|
type: 'primary', |
70
|
|
|
)]); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if (!$operation->getTargetRoute()) { |
75
|
|
|
if ($resource->hasOperation('index')) { |
76
|
|
|
$operation = $operation->withTargetRoute( |
77
|
|
|
$this->routeNameGenerator->generateRouteName($resource, $resource->getOperation('index')), |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
if (!$operation->getFormType()) { |
83
|
|
|
if ($operation instanceof Create || $operation instanceof Update) { |
84
|
|
|
$operation = $operation |
85
|
|
|
->withFormType(OperationDataType::class) |
86
|
|
|
->withFormOptions(['exclude' => $resource->getIdentifiers()]) |
87
|
|
|
; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if ($operation instanceof Index && \count($operation->getFilters() ?? []) > 0) { |
91
|
|
|
$operation = $operation |
92
|
|
|
->withFormType(ResourceFilterType::class) |
93
|
|
|
; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
if (is_a($operation->getFormType(), ResourceFilterType::class, true) && !\array_key_exists('operation', $operation->getFormOptions())) { |
98
|
|
|
$operation = $operation->withFormOptions([ |
99
|
|
|
'operation' => $operation, |
100
|
|
|
]); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
if ($operation instanceof Index) { |
104
|
|
|
if ($operation->getListActions() === null) { |
|
|
|
|
105
|
|
|
$operation = $operation->withListActions([]); |
|
|
|
|
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
$event->setOperation($operation); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
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