TYPO3 CMS  TYPO3_8-7
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 }