1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Blast Project package. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) 2015-2017 Libre Informatique |
7
|
|
|
* |
8
|
|
|
* This file is licenced under the GNU LGPL v3. |
9
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Blast\Bundle\CoreBundle\Admin\Traits; |
14
|
|
|
|
15
|
|
|
use Sonata\AdminBundle\Datagrid\ListMapper; |
16
|
|
|
|
17
|
|
|
trait Actions |
18
|
|
|
{ |
19
|
|
|
protected function addActions() |
20
|
|
|
{ |
21
|
|
|
$actionKey = '_actions'; |
22
|
|
|
$mapperClass = ListMapper::class; |
23
|
|
|
$blast = $this->getConfigurationPool()->getContainer()->getParameter('blast'); |
|
|
|
|
24
|
|
|
|
25
|
|
|
foreach ($this->getCurrentComposition() as $class) { |
|
|
|
|
26
|
|
|
if (isset($blast[$class][$mapperClass])) { |
27
|
|
|
$config = $blast[$class][$mapperClass]; |
28
|
|
|
|
29
|
|
View Code Duplication |
if (isset($blast['all'][$mapperClass])) { |
|
|
|
|
30
|
|
|
$config = array_merge_recursive( |
31
|
|
|
$config, |
32
|
|
|
$blast['all'][$mapperClass] |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
if (isset($config['add'][$actionKey])) { |
37
|
|
|
$listFields = $this->getListFieldDescriptions(); |
|
|
|
|
38
|
|
|
|
39
|
|
|
if (isset($listFields['_action'])) { |
40
|
|
|
$conf = $listFields['_action']; |
41
|
|
|
$options = $conf->getOptions(); |
42
|
|
|
$actions = $options['actions']; |
43
|
|
|
|
44
|
|
|
foreach ($config['add'][$actionKey] as $key => $action) { |
45
|
|
|
$actions[$key] = $action; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$options['actions'] = $actions; |
49
|
|
|
$conf->setOptions($options); |
50
|
|
|
$listFields['_action'] = $conf; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function removeActions() |
58
|
|
|
{ |
59
|
|
|
$blast = $this->getConfigurationPool()->getContainer()->getParameter('blast'); |
|
|
|
|
60
|
|
|
|
61
|
|
|
foreach ($this->getCurrentComposition() as $class) { |
|
|
|
|
62
|
|
|
if (!isset($blast[$class][ListMapper::class])) { |
63
|
|
|
continue; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$listFields = $this->getListFieldDescriptions(); |
|
|
|
|
67
|
|
|
if (!isset($listFields['_action'])) { |
68
|
|
|
continue; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$config = $blast[$class][ListMapper::class]; |
72
|
|
|
if (isset($blast['all'][ListMapper::class])) { |
73
|
|
|
$config = array_merge_recursive( |
74
|
|
|
$config, |
75
|
|
|
$blast['all'][ListMapper::class] |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
if (!isset($config['remove']['_actions'])) { |
79
|
|
|
continue; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$conf = $listFields['_action']; |
83
|
|
|
$options = $conf->getOptions(); |
84
|
|
|
$actions = $options['actions']; |
85
|
|
|
|
86
|
|
|
foreach ($config['remove']['_actions'] as $action) { |
87
|
|
|
if (isset($actions[$action])) { |
88
|
|
|
unset($actions[$action]); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$options['actions'] = $actions; |
93
|
|
|
$conf->setOptions($options); |
94
|
|
|
$listFields['_action'] = $conf; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
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
Idable
provides a methodequalsId
that 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.