Merge "[FEATURE] IconViewHelper (BE) should support CSS-sprites"
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Be / Buttons / IconViewHelper.php
1 <?php
2 /* *
3 * This script belongs to the FLOW3 package "Fluid". *
4 * *
5 * It is free software; you can redistribute it and/or modify it under *
6 * the terms of the GNU Lesser General Public License as published by the *
7 * Free Software Foundation, either version 3 of the License, or (at your *
8 * option) any later version. *
9 * *
10 * This script is distributed in the hope that it will be useful, but *
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
12 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
13 * General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU Lesser General Public *
16 * License along with the script. *
17 * If not, see http://www.gnu.org/licenses/lgpl.html *
18 * *
19 * The TYPO3 project - inspiring people to share! *
20 * */
21
22 /**
23 * View helper which returns save button with icon
24 * Note: This view helper is experimental!
25 *
26 * = Examples =
27 *
28 * <code title="Default">
29 * <f:be.buttons.icon uri="{f:uri.action()}" />
30 * </code>
31 * <output>
32 * An icon button as known from the TYPO3 backend, skinned and linked with the default action of the current controller.
33 * Note: By default the "close" icon is used as image
34 * </output>
35 *
36 * <code title="Default">
37 * <f:be.buttons.icon uri="{f:uri.action(action:'new')}" icon="new_el" title="Create new Foo" />
38 * </code>
39 * <output>
40 * This time the "new_el" icon is returned, the button has the title attribute set and links to the "new" action of the current controller.
41 * </output>
42 *
43 * @author Steffen Kamper <info@sk-typo3.de>
44 * @author Bastian Waidelich <bastian@typo3.org>
45 * @license http://www.gnu.org/copyleft/gpl.html
46 */
47 class Tx_Fluid_ViewHelpers_Be_Buttons_IconViewHelper extends Tx_Fluid_ViewHelpers_Be_AbstractBackendViewHelper {
48
49 /**
50 * @var array allowed icons to be used with this view helper
51 */
52 protected $allowedIcons = array('add', 'add_workspace', 'button_down', 'button_hide', 'button_left', 'button_unhide', 'button_right', 'button_up', 'clear_cache', 'clip_copy', 'clip_cut', 'clip_pasteafter', 'closedok', 'datepicker', 'deletedok', 'edit2', 'helpbubble', 'icon_fatalerror', 'icon_note', 'icon_ok', 'icon_warning', 'new_el', 'options', 'perm', 'refresh_n', 'saveandclosedok', 'savedok', 'savedoknew', 'savedokshow', 'viewdok', 'zoom');
53
54 /**
55 * Renders an icon link as known from the TYPO3 backend
56 *
57 * @param string $uri the target URI for the link. If you want to execute JavaScript here, prefix the URI with "javascript:"
58 * @param string $icon Icon to be used. See self::allowedIcons for a list of allowed icon names
59 * @param string $title Title attribte of the resulting link
60 * @return string the rendered icon link
61 */
62 public function render($uri, $icon = 'closedok', $title = '') {
63 if (!in_array($icon, $this->allowedIcons)) {
64 throw new Tx_Fluid_Core_ViewHelper_Exception('"' . $icon . '" is no valid icon. Allowed are "' . implode('", "', $this->allowedIcons) .'".', 1253208523);
65 }
66
67 return '<a href="' . $uri . '">' . t3lib_iconWorks::getSpriteIcon($icon, array('title' => $title)) . '</a>';
68 }
69 }
70 ?>