‪TYPO3CMS  10.4
ListRenderer.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 
31 {
35  protected static ‪$classes = [
36  ‪FlashMessage::NOTICE => 'notice',
37  ‪FlashMessage::INFO => 'info',
38  ‪FlashMessage::OK => 'success',
39  ‪FlashMessage::WARNING => 'warning',
40  ‪FlashMessage::ERROR => 'danger'
41  ];
42 
46  protected static ‪$icons = [
47  ‪FlashMessage::NOTICE => 'lightbulb-o',
48  ‪FlashMessage::INFO => 'info',
49  ‪FlashMessage::OK => 'check',
50  ‪FlashMessage::WARNING => 'exclamation',
51  ‪FlashMessage::ERROR => 'times'
52  ];
53 
60  public function ‪render(array $flashMessages): string
61  {
62  return $this->‪getMessageAsMarkup($flashMessages);
63  }
64 
72  protected function ‪getClass(‪FlashMessage $flashMessage): string
73  {
74  return 'alert-' . self::$classes[$flashMessage->‪getSeverity()];
75  }
76 
84  protected function ‪getIconName(‪FlashMessage $flashMessage): string
85  {
86  return ‪self::$icons[$flashMessage->‪getSeverity()];
87  }
88 
95  protected function ‪getMessageAsMarkup(array $flashMessages): string
96  {
97  $markup = [];
98  $markup[] = '<ul class="typo3-messages">';
99  foreach ($flashMessages as $flashMessage) {
100  $messageTitle = $flashMessage->getTitle();
101  $markup[] = '<li class="alert ' . htmlspecialchars($this->‪getClass($flashMessage)) . '">';
102  if ($messageTitle !== '') {
103  $markup[] = '<h4 class="alert-title">' . htmlspecialchars($messageTitle) . '</h4>';
104  }
105  $markup[] = '<p class="alert-message">' . htmlspecialchars($flashMessage->getMessage()) . '</p>';
106  $markup[] = '</li>';
107  }
108  $markup[] = '</ul>';
109  return implode('', $markup);
110  }
111 }
‪TYPO3\CMS\Core\Messaging\Renderer\ListRenderer\render
‪string render(array $flashMessages)
Definition: ListRenderer.php:58
‪TYPO3\CMS\Core\Messaging\Renderer\ListRenderer\getClass
‪string getClass(FlashMessage $flashMessage)
Definition: ListRenderer.php:70
‪TYPO3\CMS\Core\Messaging\AbstractMessage\getSeverity
‪int getSeverity()
Definition: AbstractMessage.php:96
‪TYPO3\CMS\Core\Messaging\Renderer\ListRenderer\$icons
‪static string[] $icons
Definition: ListRenderer.php:44
‪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\ListRenderer
Definition: ListRenderer.php:31
‪TYPO3\CMS\Core\Messaging\Renderer\ListRenderer\getIconName
‪string getIconName(FlashMessage $flashMessage)
Definition: ListRenderer.php:82
‪TYPO3\CMS\Core\Messaging\Renderer
Definition: BootstrapRenderer.php:18
‪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\ListRenderer\getMessageAsMarkup
‪string getMessageAsMarkup(array $flashMessages)
Definition: ListRenderer.php:93
‪TYPO3\CMS\Core\Messaging\AbstractMessage\NOTICE
‪const NOTICE
Definition: AbstractMessage.php:27
‪TYPO3\CMS\Core\Messaging\Renderer\ListRenderer\$classes
‪static string[] $classes
Definition: ListRenderer.php:34
‪$icons
‪$icons
Definition: ext_localconf.php:54
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31