|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LAG\AdminBundle\Event\Subscriber; |
|
6
|
|
|
|
|
7
|
|
|
use LAG\AdminBundle\Bridge\Doctrine\ORM\Metadata\MetadataHelperInterface; |
|
8
|
|
|
use LAG\AdminBundle\Configuration\ApplicationConfiguration; |
|
9
|
|
|
use LAG\AdminBundle\Event\AdminEvents; |
|
10
|
|
|
use LAG\AdminBundle\Event\Events\Configuration\AdminConfigurationEvent; |
|
11
|
|
|
use LAG\AdminBundle\Field\Helper\FieldConfigurationHelper; |
|
12
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
13
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Add extra default configuration for actions and fields. |
|
17
|
|
|
*/ |
|
18
|
|
|
// TODO remove this class |
|
19
|
|
|
class ExtraConfigurationSubscriber implements EventSubscriberInterface |
|
20
|
|
|
{ |
|
21
|
|
|
private ApplicationConfiguration $applicationConfiguration; |
|
22
|
|
|
private MetadataHelperInterface $metadataHelper; |
|
23
|
1 |
|
private TranslatorInterface $translator; |
|
24
|
|
|
|
|
25
|
|
|
public static function getSubscribedEvents(): array |
|
26
|
1 |
|
{ |
|
27
|
|
|
return [ |
|
28
|
|
|
AdminEvents::ADMIN_CONFIGURATION => 'enrichAdminConfiguration', |
|
29
|
|
|
]; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function __construct( |
|
33
|
|
|
ApplicationConfiguration $applicationConfiguration, |
|
34
|
|
|
MetadataHelperInterface $metadataHelper, |
|
35
|
|
|
TranslatorInterface $translator |
|
36
|
|
|
) { |
|
37
|
|
|
$this->applicationConfiguration = $applicationConfiguration; |
|
38
|
|
|
$this->metadataHelper = $metadataHelper; |
|
39
|
|
|
$this->translator = $translator; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function enrichAdminConfiguration(AdminConfigurationEvent $event): void |
|
43
|
|
|
{ |
|
44
|
|
|
if (!$this->isExtraConfigurationEnabled()) { |
|
45
|
|
|
return; |
|
46
|
|
|
} |
|
47
|
|
|
$configuration = $event->getConfiguration(); |
|
48
|
|
|
|
|
49
|
|
|
// Actions |
|
50
|
|
|
$this->addDefaultActions($configuration); |
|
51
|
|
|
|
|
52
|
|
|
// Add default field configuration: it provides a type, a form type, and a view according to the found metadata |
|
53
|
|
|
$helper = new FieldConfigurationHelper( |
|
|
|
|
|
|
54
|
|
|
$this->translator, |
|
55
|
|
|
$this->applicationConfiguration, |
|
56
|
|
|
$this->metadataHelper |
|
57
|
|
|
); |
|
58
|
|
|
//$helper->addDefaultFields($configuration, $configuration['entity'], $event->getAdminName()); |
|
59
|
|
|
$helper->addDefaultStrategy($configuration); |
|
60
|
|
|
$helper->addDefaultRouteParameters($configuration); |
|
61
|
|
|
//$helper->addDefaultFormUse($configuration); |
|
62
|
|
|
$helper->provideActionsFieldConfiguration($configuration, $event->getAdminName()); |
|
63
|
|
|
|
|
64
|
|
|
// Filters |
|
65
|
|
|
//$this->addDefaultFilters($configuration); |
|
66
|
|
|
|
|
67
|
|
|
$event->setConfiguration($configuration); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Defines the default CRUD actions if no action was configured. |
|
72
|
|
|
*/ |
|
73
|
|
|
private function addDefaultActions(array &$configuration) |
|
74
|
|
|
{ |
|
75
|
|
|
if (!\array_key_exists('actions', $configuration) || !\is_array($configuration['actions'])) { |
|
76
|
|
|
$configuration['actions'] = []; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
if (0 !== \count($configuration['actions'])) { |
|
80
|
|
|
return; |
|
81
|
|
|
} |
|
82
|
|
|
$configuration['actions'] = [ |
|
83
|
|
|
'create' => [], |
|
84
|
|
|
'list' => [], |
|
85
|
|
|
'edit' => [], |
|
86
|
|
|
'delete' => [], |
|
87
|
|
|
]; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
private function isExtraConfigurationEnabled(): bool |
|
91
|
|
|
{ |
|
92
|
|
|
// TODO |
|
93
|
|
|
return true; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|