[CLEANUP] Rework/simplify copyright header and remove @package
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Be / Buttons / IconViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Be\Buttons;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is backported from the TYPO3 Flow package "TYPO3.Fluid".
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 /**
20 * View helper which returns a button icon
21 *
22 * = Examples =
23 *
24 * <code title="Default">
25 * <f:be.buttons.icon uri="{f:uri.action()}" />
26 * </code>
27 * <output>
28 * An icon button as known from the TYPO3 backend, skinned and linked with the default action of the current controller.
29 * Note: By default the "close" icon is used as image
30 * </output>
31 *
32 * <code title="Default">
33 * <f:be.buttons.icon uri="{f:uri.action(action:'new')}" icon="actions-document-new" title="Create new Foo" />
34 * </code>
35 *
36 * <code title="Default">
37 * <f:be.buttons.icon icon="actions-document-new" title="Create new Foo" />
38 * </code>
39 * <output>
40 * Here the "actions-document-new" icon is returned, but without link.
41 * </output>
42 */
43 class IconViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper {
44
45 /**
46 * Initialize arguments
47 *
48 * @return void
49 * @api
50 */
51 public function initializeArguments() {
52 $this->registerArgument('additionalAttributes', 'array', 'Additional tag attributes. They will be added directly to the resulting HTML tag.', FALSE);
53 }
54
55 /**
56 * Renders a linked icon as known from the TYPO3 backend.
57 *
58 * If the URI is left empty, the icon is rendered without link.
59 *
60 * @param string $uri The target URI for the link. If you want to execute JavaScript here, prefix the URI with "javascript:". Leave empty to render just an icon.
61 * @param string $icon Icon to be used.
62 * @param string $title Title attribute of the icon construct
63 * @return string The rendered icon with or without link
64 */
65 public function render($uri = '', $icon = 'actions-document-close', $title = '') {
66 $additionalAttributes = '';
67 if ($this->hasArgument('additionalAttributes') && is_array($this->arguments['additionalAttributes'])) {
68 foreach ($this->arguments['additionalAttributes'] as $argumentKey => $argumentValue) {
69 $additionalAttributes .= ' ' . $argumentKey . '="' . htmlspecialchars($argumentValue) . '"';
70 }
71 }
72 $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon($icon, array('title' => $title));
73 if (empty($uri)) {
74 return $icon;
75 } else {
76 return '<a href="' . $uri . '"' . $additionalAttributes . '>' . $icon . '</a>';
77 }
78 }
79 }