‪TYPO3CMS  9.5
InfoboxViewHelper.php
Go to the documentation of this file.
1 <?php
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 
18 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
19 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
20 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
21 
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 
72  protected ‪$escapeOutput = false;
73 
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 
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 }
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: InfoboxViewHelper.php:93
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: InfoboxViewHelper.php:70
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\STATE_INFO
‪const STATE_INFO
Definition: InfoboxViewHelper.php:61
‪TYPO3\CMS\Core\Utility\MathUtility\isIntegerInRange
‪static bool isIntegerInRange($value, $minimum, $maximum)
Definition: MathUtility.php:200
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\STATE_ERROR
‪const STATE_ERROR
Definition: InfoboxViewHelper.php:64
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\STATE_WARNING
‪const STATE_WARNING
Definition: InfoboxViewHelper.php:63
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\initializeArguments
‪initializeArguments()
Definition: InfoboxViewHelper.php:77
‪TYPO3\CMS\Fluid\ViewHelpers\Be
Definition: AbstractBackendViewHelper.php:2
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\STATE_OK
‪const STATE_OK
Definition: InfoboxViewHelper.php:62
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\STATE_NOTICE
‪const STATE_NOTICE
Definition: InfoboxViewHelper.php:60
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:21
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper
Definition: InfoboxViewHelper.php:58
‪$icons
‪$icons
Definition: ext_localconf.php:77