1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Khusseini\PimcoreRadBrickBundle\Configurator; |
4
|
|
|
|
5
|
|
|
use ArrayObject; |
6
|
|
|
use Khusseini\PimcoreRadBrickBundle\RenderArgument; |
7
|
|
|
use Khusseini\PimcoreRadBrickBundle\RenderArgumentEmitter; |
8
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
9
|
|
|
|
10
|
|
|
class InstancesConfigurator extends AbstractConfigurator |
11
|
|
|
{ |
12
|
3 |
|
public function supportsEditable(string $editableName, array $config): bool |
13
|
|
|
{ |
14
|
3 |
|
return isset($config['instances']); |
15
|
|
|
} |
16
|
|
|
|
17
|
3 |
|
public function getEditablesExpressionAttributes(): array |
18
|
|
|
{ |
19
|
3 |
|
return array_merge( |
20
|
3 |
|
parent::getEditablesExpressionAttributes(), |
21
|
3 |
|
['[editable][instances]'] |
22
|
|
|
); |
23
|
|
|
} |
24
|
|
|
|
25
|
3 |
|
public function doCreateEditables( |
26
|
|
|
RenderArgumentEmitter $emitter, |
27
|
|
|
string $name, |
28
|
|
|
ConfiguratorData $data |
29
|
|
|
): void { |
30
|
3 |
|
$argument = $emitter->get($name); |
31
|
3 |
|
$config = $data->getConfig(); |
32
|
3 |
|
$instances = $config['instances']; |
33
|
|
|
|
34
|
3 |
|
if ($instances < 1) { |
35
|
1 |
|
$argument = new RenderArgument('null', $name); |
36
|
|
|
} |
37
|
|
|
|
38
|
3 |
|
if ($instances > 1) { |
39
|
1 |
|
$editables = new ArrayObject(); |
40
|
1 |
|
for ($i = 0; $i < $instances; ++$i) { |
41
|
1 |
|
$editables[] = new RenderArgument( |
42
|
1 |
|
$argument->getType(), |
43
|
1 |
|
(string) $i, |
44
|
1 |
|
$argument->getValue() |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
1 |
|
$argument = new RenderArgument('collection', $name, $editables); |
49
|
|
|
} |
50
|
|
|
|
51
|
3 |
|
$emitter->emitArgument($argument); |
52
|
3 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @codeCoverageIgnore |
56
|
|
|
*/ |
57
|
|
|
public function configureEditableOptions(OptionsResolver $or): void |
58
|
|
|
{ |
59
|
|
|
$or->setDefault('instances', 1); |
60
|
|
|
$or->setAllowedTypes('instances', ['int', 'string']); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|