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