Fixed bug #16621: Stabilize the Context Menu API (Thanks to Stefan Galinski)
[Packages/TYPO3.CMS.git] / t3lib / contextmenu / class.t3lib_contextmenu_action.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 TYPO3 Tree Team <http://forge.typo3.org/projects/typo3v4-extjstrees>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Context Menu Action
30 *
31 * @author Stefan Galinski <stefan.galinski@gmail.com>
32 * @package TYPO3
33 * @subpackage t3lib
34 */
35 class t3lib_contextmenu_Action {
36 /**
37 * Label
38 *
39 * @var string
40 */
41 protected $label = '';
42
43 /**
44 * Identifier
45 *
46 * @var string
47 */
48 protected $id = '';
49
50 /**
51 * Icon
52 *
53 * @var string
54 */
55 protected $icon = '';
56
57 /**
58 * Class
59 *
60 * @var string
61 */
62 protected $class = '';
63
64 /**
65 * Callback Action
66 *
67 * @var string
68 */
69 protected $callbackAction = '';
70
71 /**
72 * Type
73 *
74 * @var string
75 */
76 protected $type = '';
77
78 /**
79 * Child Action Collection
80 *
81 * @var t3lib_contextmenu_ActionCollection
82 */
83 protected $childActions = NULL;
84
85 /**
86 * Returns the label
87 *
88 * @return string
89 */
90 public function getLabel() {
91 return $this->label;
92 }
93
94 /**
95 * Sets the label
96 *
97 * @param string $label
98 */
99 public function setLabel($label) {
100 $this->label = $label;
101 }
102
103 /**
104 * Returns the identifier
105 *
106 * @return string
107 */
108 public function getId() {
109 return $this->id;
110 }
111
112 /**
113 * Sets the identifier
114 *
115 * @param string $id
116 */
117 public function setId($id) {
118 $this->id = $id;
119 }
120
121 /**
122 * Returns the icon
123 *
124 * @return string
125 */
126 public function getIcon() {
127 return $this->icon;
128 }
129
130 /**
131 * Sets the icon
132 *
133 * @param string $icon
134 * @return void
135 */
136 public function setIcon($icon) {
137 $this->icon = $icon;
138 }
139
140 /**
141 * Returns the class
142 *
143 * @return string
144 */
145 public function getClass() {
146 return $this->class;
147 }
148
149 /**
150 * Sets the class
151 *
152 * @param string $class
153 */
154 public function setClass($class) {
155 $this->class = $class;
156 }
157
158 /**
159 * Returns the callback action
160 *
161 * @return string
162 */
163 public function getCallbackAction() {
164 return $this->callbackAction;
165 }
166
167 /**
168 * Sets the callback action
169 *
170 * @param string $callbackAction
171 */
172 public function setCallbackAction($callbackAction) {
173 $this->callbackAction = $callbackAction;
174 }
175
176 /**
177 * Returns the type
178 *
179 * @return string
180 */
181 public function getType() {
182 return $this->type;
183 }
184
185 /**
186 * Sets the type
187 *
188 * @param string $type
189 * @return void
190 */
191 public function setType($type) {
192 $this->type = $type;
193 }
194
195 /**
196 * Returns the child actions
197 *
198 * @return t3lib_contextmenu_ActionCollection
199 */
200 public function getChildActions() {
201 return $this->childActions;
202 }
203
204 /**
205 * Sets the child actions
206 *
207 * @param t3lib_contextmenu_ActionCollection $actions
208 * @return void
209 */
210 public function setChildActions(t3lib_contextmenu_ActionCollection $actions) {
211 $this->childActions = $actions;
212 }
213
214 /**
215 * Returns true if the action has child actions
216 *
217 * @return boolean
218 */
219 public function hasChildActions() {
220 if ($this->childActions !== NULL) {
221 return TRUE;
222 }
223
224 return FALSE;
225 }
226
227 /**
228 * Returns the action as an array
229 *
230 * @return array
231 */
232 public function toArray() {
233 $arrayRepresentation = array(
234 'label' => $this->getLabel(),
235 'id' => $this->getId(),
236 'icon' => $this->getIcon(),
237 'class' => $this->getClass(),
238 'callbackAction' => $this->getCallbackAction(),
239 'type' => $this->getType(),
240 );
241
242 $arrayRepresentation['childActions'] = '';
243 if ($this->hasChildActions()) {
244 $arrayRepresentation['childActions'] = $this->childActions->toArray();
245 }
246
247 return $arrayRepresentation;
248 }
249 }
250
251 ?>