1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\PagePartBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
6
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
7
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
8
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* This is the class that validates and merges configuration from your app/config files |
12
|
|
|
* |
13
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class} |
14
|
|
|
*/ |
15
|
|
|
class Configuration implements ConfigurationInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
*/ |
20
|
2 |
|
public function getConfigTreeBuilder() |
21
|
|
|
{ |
22
|
2 |
|
$treeBuilder = new TreeBuilder('kunstmaan_page_part'); |
23
|
2 |
|
if (method_exists($treeBuilder, 'getRootNode')) { |
24
|
2 |
|
$rootNode = $treeBuilder->getRootNode(); |
25
|
|
|
} else { |
26
|
|
|
// BC layer for symfony/config 4.1 and older |
27
|
|
|
$rootNode = $treeBuilder->root('kunstmaan_page_part'); |
|
|
|
|
28
|
|
|
} |
29
|
|
|
|
30
|
2 |
|
$rootNode->children() |
31
|
2 |
|
->booleanNode('extended_pagepart_chooser') |
32
|
2 |
|
->defaultFalse() |
33
|
2 |
|
->end(); |
34
|
|
|
|
35
|
|
|
/** @var ArrayNodeDefinition $pageparts */ |
36
|
2 |
|
$pageparts = $rootNode->children()->arrayNode('pageparts')->useAttributeAsKey('index')->prototype('array'); |
37
|
2 |
|
$pageparts->children()->scalarNode('name')->isRequired(); |
38
|
2 |
|
$pageparts->children()->scalarNode('context')->isRequired(); |
39
|
2 |
|
$pageparts->children()->scalarNode('extends'); |
40
|
2 |
|
$pageparts->children()->scalarNode('widget_template'); |
41
|
|
|
|
42
|
|
|
/** @var ArrayNodeDefinition $types */ |
43
|
2 |
|
$types = $pageparts->children()->arrayNode('types')->defaultValue([])->prototype('array'); |
44
|
2 |
|
$types->children()->scalarNode('name')->isRequired(); |
45
|
2 |
|
$types->children()->scalarNode('class')->isRequired(); |
46
|
2 |
|
$types->children()->scalarNode('preview'); |
47
|
2 |
|
$types->children()->scalarNode('pagelimit'); |
48
|
|
|
|
49
|
|
|
// ************************************************************************************************************* |
50
|
|
|
|
51
|
|
|
/** @var ArrayNodeDefinition $pagetemplates */ |
52
|
2 |
|
$pagetemplates = $rootNode->children()->arrayNode('pagetemplates')->useAttributeAsKey('index')->defaultValue([])->prototype('array'); |
53
|
|
|
|
54
|
2 |
|
$pagetemplates->children()->scalarNode('template')->isRequired(); |
55
|
2 |
|
$pagetemplates->children()->scalarNode('name')->isRequired(); |
56
|
|
|
|
57
|
|
|
/** @var ArrayNodeDefinition $rows */ |
58
|
2 |
|
$rows = $pagetemplates->children()->arrayNode('rows')->prototype('array'); |
59
|
|
|
|
60
|
|
|
/** @var ArrayNodeDefinition $regions */ |
61
|
2 |
|
$regions = $rows->children()->arrayNode('regions')->prototype('array'); |
62
|
|
|
|
63
|
|
|
// no subregions this way, sorry. feel free to implement it: https://gist.github.com/Lumbendil/3249173 |
64
|
|
|
$regions |
65
|
2 |
|
->children() |
66
|
2 |
|
->scalarNode('name')->end() |
67
|
2 |
|
->scalarNode('span')->defaultValue(12)->end() |
68
|
2 |
|
->scalarNode('template')->end() |
69
|
2 |
|
->variableNode('rows') |
70
|
|
|
->validate()->ifTrue(function ($element) { |
71
|
|
|
return !\is_array($element); |
72
|
2 |
|
})->thenInvalid('The rows element must be an array.')->end() |
73
|
|
|
->validate()->always(function ($children) { |
74
|
|
|
array_walk($children, array($this, 'evaluateRows')); |
75
|
|
|
|
76
|
|
|
return $children; |
77
|
2 |
|
})->end() |
78
|
2 |
|
->end() |
79
|
2 |
|
->end(); |
80
|
|
|
|
81
|
2 |
|
return $treeBuilder; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
protected function evaluateRows(&$child, $name) |
85
|
|
|
{ |
86
|
|
|
$child = $this->getRowNode($name)->finalize($child); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
View Code Duplication |
protected function getRowNode($name = '') |
|
|
|
|
90
|
|
|
{ |
91
|
|
|
$treeBuilder = new TreeBuilder(); |
92
|
|
|
$definition = $treeBuilder->root($name); |
|
|
|
|
93
|
|
|
$this->buildRowNode($definition); |
94
|
|
|
|
95
|
|
|
return $definition->getNode(true); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
protected function buildRowNode(NodeDefinition $node) |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
return $node |
101
|
|
|
->validate()->always(function ($children) { |
102
|
|
|
array_walk($children, array($this, 'evaluateRegions')); |
103
|
|
|
|
104
|
|
|
return $children; |
105
|
|
|
}) |
106
|
|
|
->end(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
protected function evaluateRegions(&$child, $name) |
110
|
|
|
{ |
111
|
|
|
$child = $this->getRegionNode($name)->finalize($child); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
View Code Duplication |
protected function getRegionNode($name = '') |
|
|
|
|
115
|
|
|
{ |
116
|
|
|
$treeBuilder = new TreeBuilder(); |
117
|
|
|
$definition = $treeBuilder->root($name); |
|
|
|
|
118
|
|
|
$this->buildRegionNode($definition); |
119
|
|
|
|
120
|
|
|
return $definition->getNode(true); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
protected function buildRegionNode(NodeDefinition $node) |
|
|
|
|
124
|
|
|
{ |
125
|
|
|
return $node |
|
|
|
|
126
|
|
|
->children() |
127
|
|
|
->scalarNode('name')->isRequired()->end() |
128
|
|
|
->scalarNode('span')->defaultValue(12)->end() |
129
|
|
|
->variableNode('rows') |
130
|
|
|
->validate()->ifTrue(function ($element) { |
131
|
|
|
return !\is_array($element); |
132
|
|
|
})->thenInvalid('The rows element must be an array.')->end() |
133
|
|
|
->validate()->always(function ($children) { |
134
|
|
|
array_walk($children, array($this, 'evaluateRows')); |
135
|
|
|
|
136
|
|
|
return $children; |
137
|
|
|
})->end() |
138
|
|
|
->end() |
139
|
|
|
->end(); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.