1 <?php
2 /**
3 * @package Joomla.Libraries
4 * @subpackage Toolbar
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE.txt
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * Button base class
14 *
15 * The JButton is the base class for all JButton types
16 *
17 * @since 3.0
18 */
19 abstract class JToolbarButton
20 {
21 /**
22 * element name
23 *
24 * This has to be set in the final renderer classes.
25 *
26 * @var string
27 */
28 protected $_name = null;
29
30 /**
31 * reference to the object that instantiated the element
32 *
33 * @var JButton
34 */
35 protected $_parent = null;
36
37 /**
38 * Constructor
39 *
40 * @param object $parent The parent
41 */
42 public function __construct($parent = null)
43 {
44 $this->_parent = $parent;
45 }
46
47 /**
48 * Get the element name
49 *
50 * @return string type of the parameter
51 *
52 * @since 3.0
53 */
54 public function getName()
55 {
56 return $this->_name;
57 }
58
59 /**
60 * Get the HTML to render the button
61 *
62 * @param array &$definition Parameters to be passed
63 *
64 * @return string
65 *
66 * @since 3.0
67 */
68 public function render(&$definition)
69 {
70 /*
71 * Initialise some variables
72 */
73 $id = call_user_func_array(array(&$this, 'fetchId'), $definition);
74 $action = call_user_func_array(array(&$this, 'fetchButton'), $definition);
75
76 // Build id attribute
77 if ($id)
78 {
79 $id = ' id="' . $id . '"';
80 }
81
82 // Build the HTML Button
83 $options = array();
84 $options['id'] = $id;
85 $options['action'] = $action;
86
87 $layout = new JLayoutFile('joomla.toolbar.base');
88
89 return $layout->render($options);
90 }
91
92 /**
93 * Method to get the CSS class name for an icon identifier
94 *
95 * Can be redefined in the final class
96 *
97 * @param string $identifier Icon identification string
98 *
99 * @return string CSS class name
100 *
101 * @since 3.0
102 */
103 public function fetchIconClass($identifier)
104 {
105 // It's an ugly hack, but this allows templates to define the icon classes for the toolbar
106 $layout = new JLayoutFile('joomla.toolbar.iconclass');
107
108 return $layout->render(array('icon' => $identifier));
109 }
110
111 /**
112 * Get the button
113 *
114 * Defined in the final button class
115 *
116 * @return string
117 *
118 * @since 3.0
119 */
120 abstract public function fetchButton();
121 }
122
123 /**
124 * Deprecated class placeholder. You should use JToolbarButton instead.
125 *
126 * @since 1.5
127 * @deprecated 4.0 Use JToolbarButton instead.
128 * @codeCoverageIgnore
129 */
130 abstract class JButton extends JToolbarButton
131 {
132 /**
133 * Constructor
134 *
135 * @param object $parent The parent
136 *
137 * @deprecated 4.0 Use JToolbarButton instead.
138 */
139 public function __construct($parent = null)
140 {
141 JLog::add('JButton is deprecated. Use JToolbarButton instead.', JLog::WARNING, 'deprecated');
142 parent::__construct($parent);
143 }
144 }
145