|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Framework\MlComposeBundle\UiComponents; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface; |
|
6
|
|
|
use eXpansion\Framework\Core\Plugins\Gui\ActionFactory; |
|
7
|
|
|
use FML\Controls\Control; |
|
8
|
|
|
use FML\Controls\Frame; |
|
9
|
|
|
use oliverde8\AssociativeArraySimplified\AssociativeArray; |
|
10
|
|
|
use Oliverde8\PageCompose\Block\BlockDefinitionInterface; |
|
11
|
|
|
use Oliverde8\PageCompose\Service\UiComponents; |
|
12
|
|
|
use Oliverde8\PageCompose\UiComponent\AbstractUiComponent; |
|
13
|
|
|
use Symfony\Component\ExpressionLanguage\ExpressionLanguage; |
|
14
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccess; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class BaseFmlComponent |
|
18
|
|
|
* |
|
19
|
|
|
* @author de Cramer Oliver<[email protected]> |
|
20
|
|
|
* @copyright 2018 Oliverde8 |
|
21
|
|
|
* @package eXpansion\Framework\MlComposeBundle\UiComponents |
|
22
|
|
|
*/ |
|
23
|
|
|
class FmlComponent extends AbstractUiComponent |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var ActionFactory |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $actionFactory; |
|
29
|
|
|
protected $fmlClass; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct(UiComponents $uiComponents, ActionFactory $actionFactory, $fmlClass) |
|
32
|
|
|
{ |
|
33
|
|
|
parent::__construct($uiComponents); |
|
34
|
|
|
$this->propertAccess = PropertyAccess::createPropertyAccessor(); |
|
|
|
|
|
|
35
|
|
|
$this->actionFactory = $actionFactory; |
|
36
|
|
|
$this->fmlClass = $fmlClass; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Display the component. |
|
41
|
|
|
* |
|
42
|
|
|
* @param BlockDefinitionInterface $blockDefinition |
|
43
|
|
|
* @param array ...$args |
|
44
|
|
|
* |
|
45
|
|
|
* @return string |
|
46
|
|
|
*/ |
|
47
|
|
|
public function display(BlockDefinitionInterface $blockDefinition, ...$args) |
|
48
|
|
|
{ |
|
49
|
|
|
$expressionLanguage = new ExpressionLanguage(); |
|
50
|
|
|
$configuration = new AssociativeArray($blockDefinition->getConfiguration()); |
|
51
|
|
|
$class = $this->fmlClass; |
|
52
|
|
|
|
|
53
|
|
|
$arguments = [ |
|
54
|
|
|
'factory' => $args[0], |
|
55
|
|
|
'manialink' => $args[1], |
|
56
|
|
|
'args' => $args, |
|
57
|
|
|
]; |
|
58
|
|
|
|
|
59
|
|
|
/** @var Control $component */ |
|
60
|
|
|
$component = new $class($configuration->get('id', $blockDefinition->getUniqueKey())); |
|
61
|
|
|
|
|
62
|
|
|
foreach ($blockDefinition->getSubBlocks() as $block) { |
|
63
|
|
|
/** @var Frame $component */ |
|
64
|
|
|
$component->addChild($this->uiComponents->display($block, ...$args)); |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
foreach ($configuration->get('expr', []) as $key => $value) { |
|
68
|
|
|
$function = ucwords("set$key"); |
|
69
|
|
|
$component->$function($expressionLanguage->evaluate($value, $arguments)); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
View Code Duplication |
foreach ($configuration->get('args', []) as $key => $value) { |
|
|
|
|
|
|
73
|
|
|
$function = ucwords("set$key"); |
|
74
|
|
|
$component->$function(...$value); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
View Code Duplication |
foreach ($configuration->get('def', []) as $key => $value) { |
|
|
|
|
|
|
78
|
|
|
$function = ucwords("set$key"); |
|
79
|
|
|
$component->$function($value); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
if ($args[1] instanceof ManialinkInterface) { |
|
|
|
|
|
|
83
|
|
|
if ($configuration->get('action')) { |
|
84
|
|
|
$callback = [$configuration->get('action/0/service', $args[0]), $configuration->get('action/0/method')]; |
|
85
|
|
|
$this->actionFactory->createManialinkAction($args[1], $callback, [], false); |
|
86
|
|
|
} |
|
87
|
|
|
} else { |
|
|
|
|
|
|
88
|
|
|
// Log warning! |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return $component; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|