[BUGFIX] Fix several typos in php comments
[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\Core\Utility\MathUtility;
18 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
19 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
20 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
21
22 /**
23 * ViewHelper for rendering a styled content infobox markup.
24 *
25 * States
26 * ======
27 *
28 * The Infobox provides different context sensitive states that
29 * can be used to provide an additional visual feedback to the
30 * to the user to underline the meaning of the information.
31 *
32 * Possible values are in range from ``-2`` to ``2``. Please choose a
33 * meaningful value from the following list.
34 *
35 * ``-2``
36 * Notices (Default)
37 * ``-1``
38 * Information
39 * ``0``
40 * Positive feedback
41 * ``1``
42 * Warnings
43 * ``2``
44 * Error
45 *
46 * Examples
47 * ========
48 *
49 * Simple::
50 *
51 * <f:be.infobox title="Message title">your box content</f:be.infobox>
52 *
53 * All options::
54 *
55 * <f:be.infobox title="Message title" message="your box content" state="-2" iconName="check" disableIcon="true" />
56 */
57 class InfoboxViewHelper extends AbstractViewHelper
58 {
59 use CompileWithContentArgumentAndRenderStatic;
60
61 const STATE_NOTICE = -2;
62 const STATE_INFO = -1;
63 const STATE_OK = 0;
64 const STATE_WARNING = 1;
65 const STATE_ERROR = 2;
66
67 /**
68 * As this ViewHelper renders HTML, the output must not be escaped.
69 *
70 * @var bool
71 */
72 protected $escapeOutput = false;
73
74 /**
75 * Initialize arguments.
76 *
77 * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
78 */
79 public function initializeArguments()
80 {
81 $this->registerArgument('message', 'string', 'The message of the info box, if NULL tag content is used');
82 $this->registerArgument('title', 'string', 'The title of the info box');
83 $this->registerArgument('state', 'int', 'The state of the box, InfoboxViewHelper::STATE_*', false, self::STATE_NOTICE);
84 $this->registerArgument('iconName', 'string', 'The icon name from font awesome, NULL sets default icon');
85 $this->registerArgument('disableIcon', 'bool', 'If set to TRUE, the icon is not rendered.', false, false);
86 }
87
88 /**
89 * @param array $arguments
90 * @param \Closure $renderChildrenClosure
91 * @param RenderingContextInterface $renderingContext
92 *
93 * @return string
94 */
95 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
96 {
97 $title = $arguments['title'];
98 $message = $renderChildrenClosure();
99 $state = $arguments['state'];
100 $isInRange = MathUtility::isIntegerInRange($state, -2, 2);
101 if (!$isInRange) {
102 $state = -2;
103 }
104
105 $iconName = $arguments['iconName'];
106 $disableIcon = $arguments['disableIcon'];
107 $classes = [
108 self::STATE_NOTICE => 'notice',
109 self::STATE_INFO => 'info',
110 self::STATE_OK => 'success',
111 self::STATE_WARNING => 'warning',
112 self::STATE_ERROR => 'danger'
113 ];
114 $icons = [
115 self::STATE_NOTICE => 'lightbulb-o',
116 self::STATE_INFO => 'info',
117 self::STATE_OK => 'check',
118 self::STATE_WARNING => 'exclamation',
119 self::STATE_ERROR => 'times'
120 ];
121 $stateClass = $classes[$state];
122 $icon = $icons[$state];
123 if ($iconName !== null) {
124 $icon = $iconName;
125 }
126 $iconTemplate = '';
127 if (!$disableIcon) {
128 $iconTemplate = '' .
129 '<div class="media-left">' .
130 '<span class="fa-stack fa-lg callout-icon">' .
131 '<i class="fa fa-circle fa-stack-2x"></i>' .
132 '<i class="fa fa-' . htmlspecialchars($icon) . ' fa-stack-1x"></i>' .
133 '</span>' .
134 '</div>';
135 }
136 $titleTemplate = '';
137 if ($title !== null) {
138 $titleTemplate = '<h4 class="callout-title">' . htmlspecialchars($title) . '</h4>';
139 }
140 return '<div class="callout callout-' . htmlspecialchars($stateClass) . '">' .
141 '<div class="media">' .
142 $iconTemplate .
143 '<div class="media-body">' .
144 $titleTemplate .
145 '<div class="callout-body">' . $message . '</div>' .
146 '</div>' .
147 '</div>' .
148 '</div>';
149 }
150 }