‪TYPO3CMS  ‪main
InfoboxViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 use TYPO3\CMS\Core\Imaging\IconSize;
25 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
26 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
27 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
28 
64 final class ‪InfoboxViewHelper extends AbstractViewHelper
65 {
66  use CompileWithContentArgumentAndRenderStatic;
67 
68  public const ‪STATE_NOTICE = -2;
69  public const ‪STATE_INFO = -1;
70  public const ‪STATE_OK = 0;
71  public const ‪STATE_WARNING = 1;
72  public const ‪STATE_ERROR = 2;
73 
79  protected ‪$escapeOutput = false;
80 
81  public function ‪initializeArguments(): void
82  {
83  $this->registerArgument('message', 'string', 'The message of the info box, if NULL tag content is used');
84  $this->registerArgument('title', 'string', 'The title of the info box');
85  $this->registerArgument('state', 'int', 'The state of the box, InfoboxViewHelper::STATE_*', false, self::STATE_NOTICE);
86  $this->registerArgument('iconName', 'string', 'The icon name from font awesome, NULL sets default icon');
87  $this->registerArgument('disableIcon', 'bool', 'If set to TRUE, the icon is not rendered.', false, false);
88  }
89 
90  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
91  {
92  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
93  $title = $arguments['title'];
94  $message = $renderChildrenClosure();
95  $state = $arguments['state'];
96  $isInRange = ‪MathUtility::isIntegerInRange($state, -2, 2);
97  if (!$isInRange) {
98  $state = -2;
99  }
100 
101  $severity = ContextualFeedbackSeverity::from($state);
102  $disableIcon = $arguments['disableIcon'];
103  $icon = $arguments['iconName'] ?? $severity->getIconIdentifier();
104  $iconTemplate = '';
105  if (!$disableIcon) {
106  $iconTemplate = '' .
107  '<div class="media-left">' .
108  '<span class="icon-emphasized">' .
109  $iconFactory->getIcon($icon, IconSize::SMALL)->render() .
110  '</span>' .
111  '</div>';
112  }
113  $titleTemplate = '';
114  if ($title !== null) {
115  $titleTemplate = '<h4 class="callout-title">' . htmlspecialchars($title) . '</h4>';
116  }
117  return '<div class="callout callout-' . htmlspecialchars($severity->getCssClass()) . '">' .
118  '<div class="media">' .
119  $iconTemplate .
120  '<div class="media-body">' .
121  $titleTemplate .
122  '<div class="callout-body">' . $message . '</div>' .
123  '</div>' .
124  '</div>' .
125  '</div>';
126  }
127 
131  public function ‪resolveContentArgumentName(): string
132  {
133  return 'message';
134  }
135 }
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: InfoboxViewHelper.php:77
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\STATE_INFO
‪const STATE_INFO
Definition: InfoboxViewHelper.php:68
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\STATE_ERROR
‪const STATE_ERROR
Definition: InfoboxViewHelper.php:71
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\STATE_WARNING
‪const STATE_WARNING
Definition: InfoboxViewHelper.php:70
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\initializeArguments
‪initializeArguments()
Definition: InfoboxViewHelper.php:79
‪TYPO3\CMS\Fluid\ViewHelpers\Be
Definition: AbstractBackendViewHelper.php:18
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\STATE_OK
‪const STATE_OK
Definition: InfoboxViewHelper.php:69
‪TYPO3\CMS\Core\Utility\MathUtility\isIntegerInRange
‪static isIntegerInRange(mixed $value, int $minimum, int $maximum)
Definition: MathUtility.php:196
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\STATE_NOTICE
‪const STATE_NOTICE
Definition: InfoboxViewHelper.php:67
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\renderStatic
‪static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: InfoboxViewHelper.php:88
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper\resolveContentArgumentName
‪resolveContentArgumentName()
Definition: InfoboxViewHelper.php:129
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:24
‪TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper
Definition: InfoboxViewHelper.php:65
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52