|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (C) 2015-2017 Libre Informatique |
|
6
|
|
|
* |
|
7
|
|
|
* This file is licenced under the GNU LGPL v3. |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Blast\Bundle\CoreBundle\Admin\Traits; |
|
13
|
|
|
|
|
14
|
|
|
use Sonata\AdminBundle\Datagrid\ListMapper; |
|
15
|
|
|
|
|
16
|
|
|
trait Actions |
|
17
|
|
|
{ |
|
18
|
|
|
protected function addActions() |
|
19
|
|
|
{ |
|
20
|
|
|
$actionKey = '_actions'; |
|
21
|
|
|
$mapperClass = ListMapper::class; |
|
22
|
|
|
$blast = $this->getConfigurationPool()->getContainer()->getParameter('blast'); |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
foreach ($this->getCurrentComposition() as $class) { |
|
|
|
|
|
|
25
|
|
|
if (isset($blast[$class][$mapperClass])) { |
|
26
|
|
|
$config = $blast[$class][$mapperClass]; |
|
27
|
|
|
|
|
28
|
|
View Code Duplication |
if (isset($blast['all'][$mapperClass])) { |
|
|
|
|
|
|
29
|
|
|
$config = array_merge_recursive( |
|
30
|
|
|
$config, |
|
31
|
|
|
$blast['all'][$mapperClass] |
|
32
|
|
|
); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
if (isset($config['add'][$actionKey])) { |
|
36
|
|
|
$listFields = $this->getListFieldDescriptions(); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
if (isset($listFields['_action'])) { |
|
39
|
|
|
$conf = $listFields['_action']; |
|
40
|
|
|
$options = $conf->getOptions(); |
|
41
|
|
|
$actions = $options['actions']; |
|
42
|
|
|
|
|
43
|
|
|
foreach ($config['add'][$actionKey] as $key => $action) { |
|
44
|
|
|
$actions[$key] = $action; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$options['actions'] = $actions; |
|
48
|
|
|
$conf->setOptions($options); |
|
49
|
|
|
$listFields['_action'] = $conf; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
protected function removeActions() |
|
57
|
|
|
{ |
|
58
|
|
|
$blast = $this->getConfigurationPool()->getContainer()->getParameter('blast'); |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
foreach ($this->getCurrentComposition() as $class) { |
|
|
|
|
|
|
61
|
|
|
if (!isset($blast[$class][ListMapper::class])) { |
|
62
|
|
|
continue; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$listFields = $this->getListFieldDescriptions(); |
|
|
|
|
|
|
66
|
|
|
if (!isset($listFields['_action'])) { |
|
67
|
|
|
continue; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$config = $blast[$class][ListMapper::class]; |
|
71
|
|
|
if (isset($blast['all'][ListMapper::class])) { |
|
72
|
|
|
$config = array_merge_recursive( |
|
73
|
|
|
$config, |
|
74
|
|
|
$blast['all'][ListMapper::class] |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
if (!isset($config['remove']['_actions'])) { |
|
78
|
|
|
continue; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$conf = $listFields['_action']; |
|
82
|
|
|
$options = $conf->getOptions(); |
|
83
|
|
|
$actions = $options['actions']; |
|
84
|
|
|
|
|
85
|
|
|
foreach ($config['remove']['_actions'] as $action) { |
|
86
|
|
|
if (isset($actions[$action])) { |
|
87
|
|
|
unset($actions[$action]); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
$options['actions'] = $actions; |
|
92
|
|
|
$conf->setOptions($options); |
|
93
|
|
|
$listFields['_action'] = $conf; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.