TYPO3  7.6
InfoboxViewHelper.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Be;
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 = MathUtility::forceIntegerInRange($arguments['state'], -2, 2, -2);
96  $iconName = $arguments['iconName'];
97  $disableIcon = $arguments['disableIcon'];
98  if ($message === null) {
99  $messageTemplate = $renderChildrenClosure();
100  } else {
101  $messageTemplate = htmlspecialchars($message);
102  }
103  $classes = [
104  self::STATE_NOTICE => 'notice',
105  self::STATE_INFO => 'info',
106  self::STATE_OK => 'success',
107  self::STATE_WARNING => 'warning',
108  self::STATE_ERROR => 'danger'
109  ];
110  $icons = [
111  self::STATE_NOTICE => 'lightbulb-o',
112  self::STATE_INFO => 'info',
113  self::STATE_OK => 'check',
114  self::STATE_WARNING => 'exclamation',
115  self::STATE_ERROR => 'times'
116  ];
117  $stateClass = $classes[$state];
118  $icon = $icons[$state];
119  if ($iconName !== null) {
120  $icon = $iconName;
121  }
122  $iconTemplate = '';
123  if (!$disableIcon) {
124  $iconTemplate = '' .
125  '<div class="media-left">' .
126  '<span class="fa-stack fa-lg callout-icon">' .
127  '<i class="fa fa-circle fa-stack-2x"></i>' .
128  '<i class="fa fa-' . htmlspecialchars($icon) . ' fa-stack-1x"></i>' .
129  '</span>' .
130  '</div>';
131  }
132  $titleTemplate = '';
133  if ($title !== null) {
134  $titleTemplate = '<h4 class="callout-title">' . htmlspecialchars($title) . '</h4>';
135  }
136  return '<div class="callout callout-' . htmlspecialchars($stateClass) . '">' .
137  '<div class="media">' .
138  $iconTemplate .
139  '<div class="media-body">' .
140  $titleTemplate .
141  '<div class="callout-body">' . $messageTemplate . '</div>' .
142  '</div>' .
143  '</div>' .
144  '</div>';
145  }
146 }