TYPO3 CMS  TYPO3_7-6
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 
21 
53 {
54  const STATE_NOTICE = -2;
55  const STATE_INFO = -1;
56  const STATE_OK = 0;
57  const STATE_WARNING = 1;
58  const STATE_ERROR = 2;
59 
69  public function render($title = null, $message = null, $state = self::STATE_NOTICE, $iconName = null, $disableIcon = false)
70  {
71  return static::renderStatic(
72  [
73  'title' => $title,
74  'message' => $message,
75  'state' => $state,
76  'iconName' => $iconName,
77  'disableIcon' => $disableIcon
78  ],
80  $this->renderingContext
81  );
82  }
83 
92  {
93  $title = $arguments['title'];
94  $message = $arguments['message'];
95  $state = $arguments['state'];
96  $isInRange = MathUtility::isIntegerInRange($state, -2, 2);
97  if (!$isInRange) {
98  $state = -2;
99  }
100 
101  $iconName = $arguments['iconName'];
102  $disableIcon = $arguments['disableIcon'];
103  if ($message === null) {
104  $messageTemplate = $renderChildrenClosure();
105  } else {
106  $messageTemplate = htmlspecialchars($message);
107  }
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">' . $messageTemplate . '</div>' .
147  '</div>' .
148  '</div>' .
149  '</div>';
150  }
151 }
render($title=null, $message=null, $state=self::STATE_NOTICE, $iconName=null, $disableIcon=false)
static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
static isIntegerInRange($value, $minimum, $maximum)