Completed
Push — master ( af9b3a...beea93 )
by Cheren
02:12
created

ToolbarHelper::delete()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
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
    const ACTION_SAVE   = 'save';
30
31
    /**
32
     * Toolbar instance name.
33
     *
34
     * @var string
35
     */
36
    protected static $_toolbar = Toolbar::DEFAULT_NAME;
37
38
    /**
39
     * Create add link.
40
     *
41
     * @param string|null $title
42
     * @param array|string $url
43
     * @param string $icon
44
     * @param array $options
45
     * @return void
46
     */
47 View Code Duplication
    public static function add($title = null, $url = ['action' => 'add'], $icon = 'plus', array $options = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
48
    {
49
        $toolbar = Toolbar::getInstance(self::$_toolbar);
50
        $options += [
51
            'icon'   => $icon,
52
            'button' => 'green lighten-2'
53
        ];
54
55
        $toolbar->appendButton('Core.link', $title, $url, $options);
56
    }
57
58
    /**
59
     * Cancel form button.
60
     *
61
     * @param string|null $title
62
     * @param null|string|array $url
63
     * @param array $options
64
     * @return void
65
     */
66
    public static function cancel($title = null, $url = null, array $options = [])
67
    {
68
        $toolbar = Toolbar::getInstance(self::$_toolbar);
69
        $options += [
70
            'icon'      => 'close',
71
            'iconClass' => 'ckTextRed',
72
            'button'    => 'grey lighten-3'
73
        ];
74
75
        if (empty($url)) {
76
            $url = ['action' => 'index'];
77
        }
78
79
        $title = (empty($title)) ? __d('core', 'Cancel') : $title;
80
81
        $toolbar->appendButton('Core.link', $title, $url, $options);
82
    }
83
84
    /**
85
     * Delete for process form.
86
     *
87
     * @param string|null $title
88
     * @return void
89
     */
90
    public static function delete($title = null)
91
    {
92
        $toolbar = Toolbar::getInstance(self::$_toolbar);
93
        $title   = (empty($title)) ? __d('core', 'Delete') : $title;
94
95
        $toolbar->appendButton('Core.action', $title, self::ACTION_DELETE, []);
96
    }
97
98
    /**
99
     * Create link output.
100
     *
101
     * @param string $title
102
     * @param string|array $url
103
     * @param array $options
104
     */
105 View Code Duplication
    public static function link($title, $url, array $options = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
106
    {
107
        $toolbar = Toolbar::getInstance(self::$_toolbar);
108
        $options += [
109
            'icon'   => 'link',
110
            'button' => 'grey lighten-3'
111
        ];
112
113
        $toolbar->appendButton('Core.link', $title, $url, $options);
114
    }
115
116
    /**
117
     * Save form button.
118
     *
119
     * @param null|string $title
120
     * @return void
121
     */
122
    public static function save($title = null)
123
    {
124
        $toolbar = Toolbar::getInstance(self::$_toolbar);
125
        $title   = (empty($title)) ? __d('core', 'Save') : $title;
126
127
        $toolbar->appendButton('Core.action', $title, self::ACTION_SAVE, [
128
            'icon'   => 'check',
129
            'class'  => 'jsFormAdd',
130
            'button' => 'green lighten-2',
131
        ]);
132
    }
133
134
    /**
135
     * Setup toolbar instance name.
136
     *
137
     * @param string $name
138
     * @return void
139
     */
140
    public static function setToolbar($name)
141
    {
142
        self::$_toolbar = $name;
143
    }
144
}
145