|
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 Core\Utility\Toolbar; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class ToolbarHelper |
|
22
|
|
|
* |
|
23
|
|
|
* @package Core\Toolbar |
|
24
|
|
|
*/ |
|
25
|
|
|
class ToolbarHelper |
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
const ACTION_DELETE = 'delete'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Toolbar instance name. |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected static $_toolbar = Toolbar::DEFAULT_NAME; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Setup toolbar instance name. |
|
39
|
|
|
* |
|
40
|
|
|
* @param $name |
|
41
|
|
|
*/ |
|
42
|
|
|
public static function setToolbar($name) |
|
43
|
|
|
{ |
|
44
|
|
|
self::$_toolbar = $name; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Create link output. |
|
49
|
|
|
* |
|
50
|
|
|
* @param string $title |
|
51
|
|
|
* @param string $url |
|
52
|
|
|
* @param array $options |
|
53
|
|
|
*/ |
|
54
|
|
View Code Duplication |
public static function link($title, $url, array $options = []) |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
$toolbar = Toolbar::getInstance(self::$_toolbar); |
|
57
|
|
|
$options += [ |
|
58
|
|
|
'icon' => 'link', |
|
59
|
|
|
'button' => 'grey lighten-3' |
|
60
|
|
|
]; |
|
61
|
|
|
|
|
62
|
|
|
$toolbar->appendButton('Core.link', $title, $url, $options); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Create add link. |
|
67
|
|
|
* |
|
68
|
|
|
* @param string|null $title |
|
69
|
|
|
* @param array|string $url |
|
70
|
|
|
* @param string $icon |
|
71
|
|
|
* @param array $options |
|
72
|
|
|
*/ |
|
73
|
|
View Code Duplication |
public static function add($title = null, $url = ['action' => 'add'], $icon = 'plus', array $options = []) |
|
|
|
|
|
|
74
|
|
|
{ |
|
75
|
|
|
$toolbar = Toolbar::getInstance(self::$_toolbar); |
|
76
|
|
|
$options += [ |
|
77
|
|
|
'icon' => $icon, |
|
78
|
|
|
'button' => 'green lighten-2' |
|
79
|
|
|
]; |
|
80
|
|
|
|
|
81
|
|
|
$toolbar->appendButton('Core.link', $title, $url, $options); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Delete for process form. |
|
86
|
|
|
* |
|
87
|
|
|
* @param string|null $title |
|
88
|
|
|
* @param string $action |
|
89
|
|
|
*/ |
|
90
|
|
|
public static function delete($title = null, $action = self::ACTION_DELETE) |
|
91
|
|
|
{ |
|
92
|
|
|
$toolbar = Toolbar::getInstance(self::$_toolbar); |
|
93
|
|
|
$title = (empty($title)) ? __d('core', 'Delete') : $title; |
|
94
|
|
|
$toolbar->appendButton('Core.delete', $title, $action); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.