‪TYPO3CMS  10.4
BootstrapRenderer.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 
30 {
34  protected static ‪$classes = [
35  ‪FlashMessage::NOTICE => 'notice',
36  ‪FlashMessage::INFO => 'info',
37  ‪FlashMessage::OK => 'success',
38  ‪FlashMessage::WARNING => 'warning',
39  ‪FlashMessage::ERROR => 'danger'
40  ];
41 
45  protected static ‪$icons = [
46  ‪FlashMessage::NOTICE => 'lightbulb-o',
47  ‪FlashMessage::INFO => 'info',
48  ‪FlashMessage::OK => 'check',
49  ‪FlashMessage::WARNING => 'exclamation',
50  ‪FlashMessage::ERROR => 'times'
51  ];
52 
59  public function ‪render(array $flashMessages): string
60  {
61  return $this->‪getMessageAsMarkup($flashMessages);
62  }
63 
71  protected function ‪getClass(‪FlashMessage $flashMessage): string
72  {
73  return 'alert-' . self::$classes[$flashMessage->‪getSeverity()];
74  }
75 
83  protected function ‪getIconName(‪FlashMessage $flashMessage): string
84  {
85  return ‪self::$icons[$flashMessage->‪getSeverity()];
86  }
87 
94  protected function ‪getMessageAsMarkup(array $flashMessages): string
95  {
96  $markup = [];
97  $markup[] = '<div class="typo3-messages">';
98  foreach ($flashMessages as $flashMessage) {
99  $messageTitle = $flashMessage->getTitle();
100  $markup[] = '<div class="alert ' . htmlspecialchars($this->‪getClass($flashMessage)) . '">';
101  $markup[] = ' <div class="media">';
102  $markup[] = ' <div class="media-left">';
103  $markup[] = ' <span class="fa-stack fa-lg">';
104  $markup[] = ' <i class="fa fa-circle fa-stack-2x"></i>';
105  $markup[] = ' <i class="fa fa-' . htmlspecialchars($this->‪getIconName($flashMessage)) . ' fa-stack-1x"></i>';
106  $markup[] = ' </span>';
107  $markup[] = ' </div>';
108  $markup[] = ' <div class="media-body">';
109  if ($messageTitle !== '') {
110  $markup[] = ' <h4 class="alert-title">' . htmlspecialchars($messageTitle) . '</h4>';
111  }
112  $markup[] = ' <p class="alert-message">' . htmlspecialchars($flashMessage->getMessage()) . '</p>';
113  $markup[] = ' </div>';
114  $markup[] = ' </div>';
115  $markup[] = '</div>';
116  }
117  $markup[] = '</div>';
118  return implode('', $markup);
119  }
120 }
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer\getClass
‪string getClass(FlashMessage $flashMessage)
Definition: BootstrapRenderer.php:69
‪TYPO3\CMS\Core\Messaging\AbstractMessage\getSeverity
‪int getSeverity()
Definition: AbstractMessage.php:96
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer\getMessageAsMarkup
‪string getMessageAsMarkup(array $flashMessages)
Definition: BootstrapRenderer.php:92
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer\$classes
‪static string[] $classes
Definition: BootstrapRenderer.php:33
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer\$icons
‪static string[] $icons
Definition: BootstrapRenderer.php:43
‪TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING
‪const WARNING
Definition: AbstractMessage.php:30
‪TYPO3\CMS\Core\Messaging\Renderer\FlashMessageRendererInterface
Definition: FlashMessageRendererInterface.php:26
‪TYPO3\CMS\Core\Messaging\Renderer
Definition: BootstrapRenderer.php:18
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer
Definition: BootstrapRenderer.php:30
‪TYPO3\CMS\Core\Messaging\AbstractMessage\OK
‪const OK
Definition: AbstractMessage.php:29
‪TYPO3\CMS\Core\Messaging\AbstractMessage\INFO
‪const INFO
Definition: AbstractMessage.php:28
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer\render
‪string render(array $flashMessages)
Definition: BootstrapRenderer.php:57
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer\getIconName
‪string getIconName(FlashMessage $flashMessage)
Definition: BootstrapRenderer.php:81
‪TYPO3\CMS\Core\Messaging\AbstractMessage\NOTICE
‪const NOTICE
Definition: AbstractMessage.php:27
‪$icons
‪$icons
Definition: ext_localconf.php:54
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31