[BUGFIX] Use late static binding for compilable viewhelpers
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Be / InfoboxViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Be;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
18 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
19 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
20
21
22 /**
23 * View helper for rendering a styled content infobox markup.
24 *
25 * = States =
26 *
27 * The Infobox provides different context sensitive states that
28 * can be used to provide an additional visual feedback to the
29 * to the user to underline the meaning of the information.
30 *
31 * Possible values are in range from -2 to 2. Please choose a
32 * meaningful value from the following list.
33 *
34 * -2: Notices (Default)
35 * -1: Information
36 * 0: Positive feedback
37 * 1: Warnings
38 * 2: Error
39 *
40 * = Examples =
41 *
42 * <code title="Simple">
43 * <f:be.infobox title="Message title">your box content</f:be.infobox>
44 * </code>
45 *
46 * <code title="All options">
47 * <f:be.infobox title="Message title" message="your box content" state="-2" iconName="check" disableIcon="TRUE" />
48 * </code>
49 *
50 * @api
51 */
52 class InfoboxViewHelper extends AbstractViewHelper implements CompilableInterface {
53
54 const STATE_NOTICE = -2;
55 const STATE_INFO = -1;
56 const STATE_OK = 0;
57 const STATE_WARNING = 1;
58 const STATE_ERROR = 2;
59
60 /**
61 * @param string $title The title of the infobox
62 * @param string $message The message of the infobox, if NULL tag content is used
63 * @param int $state The state of the box, InfoboxViewHelper::STATE_*
64 * @param string $iconName The icon name from fontawsome, NULL sets default icon
65 * @param bool $disableIcon If set to TRUE, the icon is not rendered.
66 *
67 * @return string
68 */
69 public function render($title = NULL, $message = NULL, $state = self::STATE_NOTICE, $iconName = NULL, $disableIcon = FALSE) {
70 return static::renderStatic(
71 array(
72 'title' => $title,
73 'message' => $message,
74 'state' => $state,
75 'iconName' => $iconName,
76 'disableIcon' => $disableIcon
77 ),
78 $this->buildRenderChildrenClosure(),
79 $this->renderingContext
80 );
81 }
82
83 /**
84 * @param array $arguments
85 * @param callable $renderChildrenClosure
86 * @param RenderingContextInterface $renderingContext
87 *
88 * @return string
89 * @throws Exception
90 */
91 static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
92 $title = $arguments['title'];
93 $message = $arguments['message'];
94 $state = $arguments['state'];
95 $iconName = $arguments['iconName'];
96 $disableIcon = $arguments['disableIcon'];
97
98 if ($message === NULL) {
99 $message = $renderChildrenClosure();
100 }
101 switch ($state) {
102 case self::STATE_NOTICE:
103 $stateClass = 'notice';
104 $icon = 'lightbulb-o';
105 break;
106 case self::STATE_INFO:
107 $stateClass = 'info';
108 $icon = 'info';
109 break;
110 case self::STATE_OK:
111 $stateClass = 'success';
112 $icon = 'check';
113 break;
114 case self::STATE_WARNING:
115 $stateClass = 'warning';
116 $icon = 'exclamation';
117 break;
118 case self::STATE_ERROR:
119 $stateClass = 'danger';
120 $icon = 'times';
121 break;
122 default:
123 $stateClass = 'notice';
124 $icon = 'lightbulb-o';
125 }
126 if ($iconName !== NULL) {
127 $icon = htmlspecialchars($iconName);
128 }
129 $iconTemplate = '';
130 if (!$disableIcon) {
131 $iconTemplate = '' .
132 '<div class="media-left">' .
133 '<span class="fa-stack fa-lg callout-icon">' .
134 '<i class="fa fa-circle fa-stack-2x"></i>' .
135 '<i class="fa fa-' . $icon . ' fa-stack-1x"></i>' .
136 '</span>' .
137 '</div>';
138 }
139 $titleTemplate = '';
140 if ($title !== NULL) {
141 $titleTemplate = '<h4 class="callout-title">' . $title . '</h4>';
142 }
143 return '<div class="callout callout-' . $stateClass . '">' .
144 '<div class="media">' .
145 $iconTemplate .
146 '<div class="media-body">' .
147 $titleTemplate .
148 '<div class="callout-body">' . $message . '</div>' .
149 '</div>' .
150 '</div>' .
151 '</div>';
152 }
153
154 }