Completed
Push — master ( b26fc8...c06b74 )
by Cheren
02:20
created

ToolbarItem::fetchButton()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 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
use Core\View\ButtonView;
20
use Cake\Utility\Inflector;
21
22
/**
23
 * Class ToolbarItem
24
 *
25
 * @package Core\Toolbar
26
 */
27
abstract class ToolbarItem
28
{
29
30
    /**
31
     * Reference to the object that instantiated the element.
32
     *
33
     * @var Toolbar|null
34
     */
35
    protected $_parent = null;
36
37
    /**
38
     * Button view object.
39
     *
40
     * @var ButtonView
41
     */
42
    protected $_view;
43
44
    /**
45
     * ToolbarButton constructor.
46
     *
47
     * @param null|Toolbar $parent
48
     */
49
    public function __construct($parent = null)
50
    {
51
        $this->_parent = $parent;
52
        $this->_view   = new ButtonView();
53
    }
54
55
    /**
56
     * Get the button output.
57
     *
58
     * @return string
59
     */
60
    abstract public function fetchButton();
61
62
    /**
63
     * Fetch button id.
64
     *
65
     * @param string $type
66
     * @param string $name
67
     * @return string
68
     * @SuppressWarnings("unused")
69
     */
70
    public function fetchId($type, $name)
71
    {
72
        return Inflector::dasherize($this->_parent->getName()) . '-' . $name;
73
    }
74
75
    /**
76
     * Render toolbar html.
77
     *
78
     * @param array $node
79
     * @return string
80
     */
81
    public function render(&$node)
82
    {
83
        $id = call_user_func_array([&$this, 'fetchId'], $node);
84
        $output = call_user_func_array([&$this, 'fetchButton'], $node);
85
86
        $options = [
87
            'id'     => $id,
88
            'output' => $output,
89
        ];
90
91
        return $this->_view->element('Toolbar/wrapper', $options);
92
    }
93
}
94