|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* CakeCMS Core |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of the of the simple cms based on CakePHP 3. |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
* |
|
9
|
|
|
* @package Core |
|
10
|
|
|
* @license MIT |
|
11
|
|
|
* @copyright MIT License http://www.opensource.org/licenses/mit-license.php |
|
12
|
|
|
* @link https://github.com/CakeCMS/Core". |
|
13
|
|
|
* @author Sergey Kalistratov <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Core\Toolbar; |
|
17
|
|
|
|
|
18
|
|
|
use JBZoo\Utils\Str; |
|
19
|
|
|
use Core\Utility\Toolbar; |
|
20
|
|
|
use Core\View\ButtonView; |
|
21
|
|
|
use Cake\Utility\Inflector; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class ToolbarItem |
|
25
|
|
|
* |
|
26
|
|
|
* @package Core\Toolbar |
|
27
|
|
|
*/ |
|
28
|
|
|
abstract class ToolbarItem |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Reference to the object that instantiated the element. |
|
33
|
|
|
* |
|
34
|
|
|
* @var Toolbar|null |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $_parent = null; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Button view object. |
|
40
|
|
|
* |
|
41
|
|
|
* @var ButtonView |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $_view; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* ToolbarButton constructor. |
|
47
|
|
|
* |
|
48
|
|
|
* @param null|Toolbar $parent |
|
49
|
|
|
*/ |
|
50
|
|
|
public function __construct($parent = null) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->_parent = $parent; |
|
53
|
|
|
$this->_view = new ButtonView(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Fetch button id. |
|
58
|
|
|
* |
|
59
|
|
|
* @param string $type |
|
60
|
|
|
* @param string $name |
|
61
|
|
|
* @return string |
|
62
|
|
|
* @SuppressWarnings("unused") |
|
63
|
|
|
*/ |
|
64
|
|
|
public function fetchId($type, $name) |
|
|
|
|
|
|
65
|
|
|
{ |
|
66
|
|
|
return Inflector::dasherize($this->_parent->getName()) . '-' . Str::slug($type); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Get the item output. |
|
71
|
|
|
* |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
|
|
abstract public function fetchItem(); |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Render toolbar html. |
|
78
|
|
|
* |
|
79
|
|
|
* @param array $node |
|
80
|
|
|
* @return string |
|
81
|
|
|
*/ |
|
82
|
|
|
public function render(&$node) |
|
83
|
|
|
{ |
|
84
|
|
|
$id = call_user_func_array([&$this, 'fetchId'], $node); |
|
85
|
|
|
$output = call_user_func_array([&$this, 'fetchItem'], $node); |
|
86
|
|
|
list ($source) = $node; |
|
87
|
|
|
list ($plugin) = pluginSplit($source); |
|
88
|
|
|
|
|
89
|
|
|
$options = [ |
|
90
|
|
|
'id' => $id, |
|
91
|
|
|
'output' => $output, |
|
92
|
|
|
'class' => $node['class'], |
|
93
|
|
|
]; |
|
94
|
|
|
|
|
95
|
|
|
$element = 'Toolbar/wrapper'; |
|
96
|
|
|
if ($plugin !== null) { |
|
97
|
|
|
$element = $plugin . '.' . $element; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return $this->_view->element($element, $options); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.