|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LAG\AdminBundle\Field\Field; |
|
4
|
|
|
|
|
5
|
|
|
use LAG\AdminBundle\Field\AbstractField; |
|
6
|
|
|
use LAG\AdminBundle\Field\Configuration\ActionCollectionConfiguration; |
|
7
|
|
|
use LAG\AdminBundle\Field\EntityAwareInterface; |
|
8
|
|
|
use LAG\AdminBundle\Field\TwigAwareInterface; |
|
9
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccess; |
|
10
|
|
|
use Twig_Environment; |
|
11
|
|
|
|
|
12
|
|
|
class ActionCollection extends AbstractField implements TwigAwareInterface, EntityAwareInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var Twig_Environment |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $twig; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var mixed |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $entity; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Render value of the field. |
|
26
|
|
|
* |
|
27
|
|
|
* @param mixed $value Value to render |
|
28
|
|
|
* |
|
29
|
|
|
* @return mixed |
|
30
|
|
|
*/ |
|
31
|
|
|
public function render($value) |
|
32
|
|
|
{ |
|
33
|
|
|
$actions = $this->options['actions']; |
|
34
|
|
|
$normalizedActions = []; |
|
35
|
|
|
|
|
36
|
|
|
foreach ($actions as $action => $options) { |
|
37
|
|
|
$accessor = PropertyAccess::createPropertyAccessor(); |
|
38
|
|
|
$normalizedParameters = []; |
|
39
|
|
|
|
|
40
|
|
|
foreach ($options['parameters'] as $parameter => $parameterOptions) { |
|
41
|
|
|
$normalizedParameters[$parameter] = $accessor->getValue($this->entity, $parameter); |
|
42
|
|
|
} |
|
43
|
|
|
$options['parameters'] = $normalizedParameters; |
|
44
|
|
|
$normalizedActions[$action] = $options; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return $this |
|
48
|
|
|
->twig |
|
49
|
|
|
->render('@LAGAdmin/Field/actionCollection.html.twig', [ |
|
50
|
|
|
'actions' => $normalizedActions, |
|
51
|
|
|
]) |
|
52
|
|
|
; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Return field type. |
|
57
|
|
|
* |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getType() |
|
61
|
|
|
{ |
|
62
|
|
|
return AbstractField::TYPE_ACTION_COLLECTION; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Defines entity for field. |
|
67
|
|
|
* |
|
68
|
|
|
* @param $entity |
|
69
|
|
|
* |
|
70
|
|
|
* @return void |
|
71
|
|
|
*/ |
|
72
|
|
|
public function setEntity($entity) |
|
73
|
|
|
{ |
|
74
|
|
|
$this->entity = $entity; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Define twig environment. |
|
79
|
|
|
* |
|
80
|
|
|
* @param Twig_Environment $twig |
|
81
|
|
|
* |
|
82
|
|
|
* @return void |
|
83
|
|
|
*/ |
|
84
|
|
|
public function setTwig(Twig_Environment $twig) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->twig = $twig; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Return the Field's configuration class. |
|
91
|
|
|
* |
|
92
|
|
|
* @return string |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getConfigurationClass() |
|
95
|
|
|
{ |
|
96
|
|
|
return ActionCollectionConfiguration::class; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|