TYPO3 CMS  TYPO3_8-7
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  */
20 
50 {
52 
53  const STATE_NOTICE = -2;
54  const STATE_INFO = -1;
55  const STATE_OK = 0;
56  const STATE_WARNING = 1;
57  const STATE_ERROR = 2;
58 
64  protected $escapeOutput = false;
65 
71  public function initializeArguments()
72  {
73  parent::initializeArguments();
74  $this->registerArgument('message', 'string', 'The message of the info box, if NULL tag content is used');
75  $this->registerArgument('title', 'string', 'The title of the info box');
76  $this->registerArgument('state', 'int', 'The state of the box, InfoboxViewHelper::STATE_*', false, self::STATE_NOTICE);
77  $this->registerArgument('iconName', 'string', 'The icon name from font awesome, NULL sets default icon');
78  $this->registerArgument('disableIcon', 'bool', 'If set to TRUE, the icon is not rendered.', false, false);
79  }
80 
88  public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
89  {
90  $title = $arguments['title'];
91  $message = $renderChildrenClosure();
92  $state = $arguments['state'];
93  $isInRange = MathUtility::isIntegerInRange($state, -2, 2);
94  if (!$isInRange) {
95  $state = -2;
96  }
97 
98  $iconName = $arguments['iconName'];
99  $disableIcon = $arguments['disableIcon'];
100  $classes = [
101  self::STATE_NOTICE => 'notice',
102  self::STATE_INFO => 'info',
103  self::STATE_OK => 'success',
104  self::STATE_WARNING => 'warning',
105  self::STATE_ERROR => 'danger'
106  ];
107  $icons = [
108  self::STATE_NOTICE => 'lightbulb-o',
109  self::STATE_INFO => 'info',
110  self::STATE_OK => 'check',
111  self::STATE_WARNING => 'exclamation',
112  self::STATE_ERROR => 'times'
113  ];
114  $stateClass = $classes[$state];
115  $icon = $icons[$state];
116  if ($iconName !== null) {
117  $icon = $iconName;
118  }
119  $iconTemplate = '';
120  if (!$disableIcon) {
121  $iconTemplate = '' .
122  '<div class="media-left">' .
123  '<span class="fa-stack fa-lg callout-icon">' .
124  '<i class="fa fa-circle fa-stack-2x"></i>' .
125  '<i class="fa fa-' . htmlspecialchars($icon) . ' fa-stack-1x"></i>' .
126  '</span>' .
127  '</div>';
128  }
129  $titleTemplate = '';
130  if ($title !== null) {
131  $titleTemplate = '<h4 class="callout-title">' . htmlspecialchars($title) . '</h4>';
132  }
133  return '<div class="callout callout-' . htmlspecialchars($stateClass) . '">' .
134  '<div class="media">' .
135  $iconTemplate .
136  '<div class="media-body">' .
137  $titleTemplate .
138  '<div class="callout-body">' . $message . '</div>' .
139  '</div>' .
140  '</div>' .
141  '</div>';
142  }
143 }
static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
static isIntegerInRange($value, $minimum, $maximum)