‪TYPO3CMS  11.5
InfoboxViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
20 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
22 
58 class ‪InfoboxViewHelper extends AbstractViewHelper
59 {
60  use CompileWithContentArgumentAndRenderStatic;
61 
62  public const ‪STATE_NOTICE = -2;
63  public const ‪STATE_INFO = -1;
64  public const ‪STATE_OK = 0;
65  public const ‪STATE_WARNING = 1;
66  public const ‪STATE_ERROR = 2;
67 
73  protected ‪$escapeOutput = false;
74 
80  public function ‪initializeArguments()
81  {
82  $this->registerArgument('message', 'string', 'The message of the info box, if NULL tag content is used');
83  $this->registerArgument('title', 'string', 'The title of the info box');
84  $this->registerArgument('state', 'int', 'The state of the box, InfoboxViewHelper::STATE_*', false, self::STATE_NOTICE);
85  $this->registerArgument('iconName', 'string', 'The icon name from font awesome, NULL sets default icon');
86  $this->registerArgument('disableIcon', 'bool', 'If set to TRUE, the icon is not rendered.', false, false);
87  }
88 
96  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
97  {
98  $title = $arguments['title'];
99  $message = $renderChildrenClosure();
100  $state = $arguments['state'];
101  $isInRange = ‪MathUtility::isIntegerInRange($state, -2, 2);
102  if (!$isInRange) {
103  $state = -2;
104  }
105 
106  $iconName = $arguments['iconName'];
107  $disableIcon = $arguments['disableIcon'];
108  $classes = [
109  self::STATE_NOTICE => 'notice',
110  self::STATE_INFO => 'info',
111  self::STATE_OK => 'success',
112  self::STATE_WARNING => 'warning',
113  self::STATE_ERROR => 'danger',
114  ];
115  $icons = [
116  self::STATE_NOTICE => 'lightbulb-o',
117  self::STATE_INFO => 'info',
118  self::STATE_OK => 'check',
119  self::STATE_WARNING => 'exclamation',
120  self::STATE_ERROR => 'times',
121  ];
122  $stateClass = $classes[$state];
123  $icon = $icons[$state];
124  if ($iconName !== null) {
125  $icon = $iconName;
126  }
127  $iconTemplate = '';
128  if (!$disableIcon) {
129  $iconTemplate = '' .
130  '<div class="media-left">' .
131  '<span class="fa-stack fa-lg callout-icon">' .
132  '<i class="fa fa-circle fa-stack-2x"></i>' .
133  '<i class="fa fa-' . htmlspecialchars($icon) . ' fa-stack-1x"></i>' .
134  '</span>' .
135  '</div>';
136  }
137  $titleTemplate = '';
138  if ($title !== null) {
139  $titleTemplate = '<h4 class="callout-title">' . htmlspecialchars($title) . '</h4>';
140  }
141  return '<div class="callout callout-' . htmlspecialchars($stateClass) . '">' .
142  '<div class="media">' .
143  $iconTemplate .
144  '<div class="media-body">' .
145  $titleTemplate .
146  '<div class="callout-body">' . $message . '</div>' .
147  '</div>' .
148  '</div>' .
149  '</div>';
150  }
151 }
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: InfoboxViewHelper.php:94
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: InfoboxViewHelper.php:71
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\STATE_INFO
‪const STATE_INFO
Definition: InfoboxViewHelper.php:62
‪TYPO3\CMS\Core\Utility\MathUtility\isIntegerInRange
‪static bool isIntegerInRange($value, $minimum, $maximum)
Definition: MathUtility.php:202
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\STATE_ERROR
‪const STATE_ERROR
Definition: InfoboxViewHelper.php:65
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\STATE_WARNING
‪const STATE_WARNING
Definition: InfoboxViewHelper.php:64
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\initializeArguments
‪initializeArguments()
Definition: InfoboxViewHelper.php:78
‪TYPO3\CMS\Fluid\ViewHelpers\Be
Definition: AbstractBackendViewHelper.php:16
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\STATE_OK
‪const STATE_OK
Definition: InfoboxViewHelper.php:63
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\STATE_NOTICE
‪const STATE_NOTICE
Definition: InfoboxViewHelper.php:61
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper
Definition: InfoboxViewHelper.php:59