|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the ekino Drupal Debug project. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) ekino |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Ekino\Drupal\Debug\Configuration; |
|
15
|
|
|
|
|
16
|
|
|
use Ekino\Drupal\Debug\ActionMetadata\Model\ActionMetadata; |
|
17
|
|
|
use Ekino\Drupal\Debug\ActionMetadata\Model\ActionWithOptionsMetadata; |
|
18
|
|
|
use Ekino\Drupal\Debug\Configuration\Model\DefaultsConfiguration as DefaultsConfigurationModel; |
|
19
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
20
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
21
|
|
|
|
|
22
|
|
|
class ActionsConfiguration extends AbstractConfiguration |
|
23
|
|
|
{ |
|
24
|
|
|
public const ROOT_KEY = 'actions'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var ActionMetadata[] |
|
28
|
|
|
*/ |
|
29
|
|
|
private $actionsMetadata; |
|
30
|
|
|
|
|
31
|
|
|
private $defaultsConfiguration; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param ActionMetadata[] $actionsMetadata |
|
35
|
|
|
* @param DefaultsConfigurationModel $defaultsConfiguration |
|
36
|
|
|
*/ |
|
37
|
18 |
|
public function __construct(array $actionsMetadata, DefaultsConfigurationModel $defaultsConfiguration) |
|
38
|
|
|
{ |
|
39
|
18 |
|
$this->actionsMetadata = $actionsMetadata; |
|
40
|
18 |
|
$this->defaultsConfiguration = $defaultsConfiguration; |
|
41
|
18 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritdoc} |
|
45
|
|
|
*/ |
|
46
|
18 |
|
public function getArrayNodeDefinition(TreeBuilder $treeBuilder): ArrayNodeDefinition |
|
47
|
|
|
{ |
|
48
|
|
|
/** @var ArrayNodeDefinition $rootNode */ |
|
49
|
18 |
|
$rootNode = $treeBuilder->root(self::ROOT_KEY); |
|
50
|
|
|
$nodeBuilder = $rootNode |
|
51
|
18 |
|
->addDefaultsIfNotSet() |
|
52
|
18 |
|
->children(); |
|
53
|
|
|
|
|
54
|
18 |
|
foreach ($this->actionsMetadata as $actionMetadata) { |
|
55
|
|
|
$childrenNodeBuilder = $nodeBuilder |
|
56
|
18 |
|
->arrayNode($actionMetadata->getShortName()) |
|
57
|
18 |
|
->canBeDisabled() |
|
58
|
18 |
|
->children(); |
|
59
|
|
|
|
|
60
|
18 |
|
if ($actionMetadata instanceof ActionWithOptionsMetadata) { |
|
61
|
18 |
|
$actionMetadata->getOptionsClass()::addConfiguration($childrenNodeBuilder, $this->defaultsConfiguration); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$childrenNodeBuilder |
|
65
|
18 |
|
->end(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$rootNode |
|
69
|
18 |
|
->end(); |
|
70
|
|
|
|
|
71
|
18 |
|
return $rootNode; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|