‪TYPO3CMS  9.5
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 }
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer\$classes
‪static string $classes
Definition: BootstrapRenderer.php:31
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer\getClass
‪string getClass(FlashMessage $flashMessage)
Definition: BootstrapRenderer.php:67
‪TYPO3\CMS\Core\Messaging\AbstractMessage\getSeverity
‪int getSeverity()
Definition: AbstractMessage.php:94
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer\getMessageAsMarkup
‪string getMessageAsMarkup(array $flashMessages)
Definition: BootstrapRenderer.php:90
‪TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING
‪const WARNING
Definition: AbstractMessage.php:28
‪TYPO3\CMS\Core\Messaging\Renderer\FlashMessageRendererInterface
Definition: FlashMessageRendererInterface.php:24
‪TYPO3\CMS\Core\Messaging\Renderer
Definition: BootstrapRenderer.php:3
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer
Definition: BootstrapRenderer.php:28
‪TYPO3\CMS\Core\Messaging\AbstractMessage\OK
‪const OK
Definition: AbstractMessage.php:27
‪TYPO3\CMS\Core\Messaging\AbstractMessage\INFO
‪const INFO
Definition: AbstractMessage.php:26
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:22
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer\render
‪string render(array $flashMessages)
Definition: BootstrapRenderer.php:55
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer\getIconName
‪string getIconName(FlashMessage $flashMessage)
Definition: BootstrapRenderer.php:79
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer\$icons
‪static string $icons
Definition: BootstrapRenderer.php:41
‪TYPO3\CMS\Core\Messaging\AbstractMessage\NOTICE
‪const NOTICE
Definition: AbstractMessage.php:25
‪$icons
‪$icons
Definition: ext_localconf.php:77
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:29