‪TYPO3CMS  ‪main
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 use TYPO3\CMS\Core\Imaging\IconSize;
24 
33 {
35 
37  {
38  $this->iconFactory = ‪$iconFactory ?? GeneralUtility::makeInstance(IconFactory::class);
39  }
40 
47  public function ‪render(array $flashMessages): string
48  {
49  return $this->‪getMessageAsMarkup($flashMessages);
50  }
51 
58  protected function ‪getClass(‪FlashMessage $flashMessage): string
59  {
60  return 'alert-' . $flashMessage->‪getSeverity()->getCssClass();
61  }
62 
69  protected function ‪getIconName(‪FlashMessage $flashMessage): string
70  {
71  return $flashMessage->‪getSeverity()->getIconIdentifier();
72  }
73 
79  protected function ‪getMessageAsMarkup(array $flashMessages): string
80  {
81  $markup = [];
82  $markup[] = '<div class="typo3-messages">';
83  foreach ($flashMessages as $flashMessage) {
84  $messageTitle = $flashMessage->getTitle();
85  $markup[] = '<div class="alert ' . htmlspecialchars($this->‪getClass($flashMessage)) . '">';
86  $markup[] = ' <div class="media">';
87  $markup[] = ' <div class="media-left">';
88  $markup[] = ' <span class="icon-emphasized">';
89  $markup[] = $this->iconFactory->getIcon($this->‪getIconName($flashMessage), IconSize::SMALL)->render();
90  $markup[] = ' </span>';
91  $markup[] = ' </div>';
92  $markup[] = ' <div class="media-body">';
93  if ($messageTitle !== '') {
94  $markup[] = ' <h4 class="alert-title">' . htmlspecialchars($messageTitle) . '</h4>';
95  }
96  $markup[] = ' <p class="alert-message">' . htmlspecialchars($flashMessage->getMessage()) . '</p>';
97  $markup[] = ' </div>';
98  $markup[] = ' </div>';
99  $markup[] = '</div>';
100  }
101  $markup[] = '</div>';
102  return implode('', $markup);
103  }
104 }
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer\getClass
‪string getClass(FlashMessage $flashMessage)
Definition: BootstrapRenderer.php:58
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer\$iconFactory
‪IconFactory $iconFactory
Definition: BootstrapRenderer.php:34
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Core\Messaging\AbstractMessage\getSeverity
‪getSeverity()
Definition: AbstractMessage.php:54
‪TYPO3\CMS\Core\Messaging\Renderer\FlashMessageRendererInterface
Definition: FlashMessageRendererInterface.php:26
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer\__construct
‪__construct(IconFactory $iconFactory=null)
Definition: BootstrapRenderer.php:36
‪TYPO3\CMS\Core\Messaging\Renderer
Definition: BootstrapRenderer.php:18
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer
Definition: BootstrapRenderer.php:33
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:27
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer\render
‪string render(array $flashMessages)
Definition: BootstrapRenderer.php:47
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer\getIconName
‪string getIconName(FlashMessage $flashMessage)
Definition: BootstrapRenderer.php:69
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer\getMessageAsMarkup
‪getMessageAsMarkup(array $flashMessages)
Definition: BootstrapRenderer.php:79
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52