TYPO3 CMS  TYPO3_8-7
BootstrapRenderer.php
Go to the documentation of this file.
1 <?php
2 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 
28 {
32  protected static $classes = [
33  FlashMessage::NOTICE => 'notice',
34  FlashMessage::INFO => 'info',
35  FlashMessage::OK => 'success',
36  FlashMessage::WARNING => 'warning',
37  FlashMessage::ERROR => 'danger'
38  ];
39 
43  protected static $icons = [
44  FlashMessage::NOTICE => 'lightbulb-o',
45  FlashMessage::INFO => 'info',
46  FlashMessage::OK => 'check',
47  FlashMessage::WARNING => 'exclamation',
48  FlashMessage::ERROR => 'times'
49  ];
50 
57  public function render(array $flashMessages): string
58  {
59  return $this->getMessageAsMarkup($flashMessages);
60  }
61 
69  protected function getClass(FlashMessage $flashMessage): string
70  {
71  return 'alert-' . self::$classes[$flashMessage->getSeverity()];
72  }
73 
81  protected function getIconName(FlashMessage $flashMessage): string
82  {
83  return self::$icons[$flashMessage->getSeverity()];
84  }
85 
92  protected function getMessageAsMarkup(array $flashMessages): string
93  {
94  $markup = [];
95  $markup[] = '<div class="typo3-messages">';
96  foreach ($flashMessages as $flashMessage) {
97  $messageTitle = $flashMessage->getTitle();
98  $markup[] = '<div class="alert ' . htmlspecialchars($this->getClass($flashMessage)) . '">';
99  $markup[] = ' <div class="media">';
100  $markup[] = ' <div class="media-left">';
101  $markup[] = ' <span class="fa-stack fa-lg">';
102  $markup[] = ' <i class="fa fa-circle fa-stack-2x"></i>';
103  $markup[] = ' <i class="fa fa-' . htmlspecialchars($this->getIconName($flashMessage)) . ' fa-stack-1x"></i>';
104  $markup[] = ' </span>';
105  $markup[] = ' </div>';
106  $markup[] = ' <div class="media-body">';
107  if ($messageTitle !== '') {
108  $markup[] = ' <h4 class="alert-title">' . htmlspecialchars($messageTitle) . '</h4>';
109  }
110  $markup[] = ' <p class="alert-message">' . htmlspecialchars($flashMessage->getMessage()) . '</p>';
111  $markup[] = ' </div>';
112  $markup[] = ' </div>';
113  $markup[] = '</div>';
114  }
115  $markup[] = '</div>';
116  return implode('', $markup);
117  }
118 }