‪TYPO3CMS  9.5
FlashMessageFinisher.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 originated from the Neos.Form package (www.neos.io)
9  *
10  * It is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU General Public License, either version 2
12  * of the License, or any later version.
13  *
14  * For the full copyright and license information, please read the
15  * LICENSE.txt file that was distributed with this source code.
16  *
17  * The TYPO3 project - inspiring people to share!
18  */
19 
27 
48 {
49 
53  protected ‪$defaultOptions = [
54  'messageBody' => null,
55  'messageTitle' => '',
56  'messageArguments' => [],
57  'messageCode' => null,
58  'severity' => ‪AbstractMessage::OK,
59  ];
60 
67  protected function ‪executeInternal()
68  {
69  $messageBody = $this->‪parseOption('messageBody');
70  if (!is_string($messageBody)) {
71  throw new ‪FinisherException(sprintf('The message body must be of type string, "%s" given.', gettype($messageBody)), 1335980069);
72  }
73  $messageTitle = $this->‪parseOption('messageTitle');
74  $messageArguments = $this->‪parseOption('messageArguments');
75  $messageCode = $this->‪parseOption('messageCode');
76  $severity = $this->‪parseOption('severity');
77  switch ($severity) {
79  $message = $this->objectManager->get(Notice::class, $messageBody, $messageCode, $messageArguments, $messageTitle);
80  break;
82  $message = $this->objectManager->get(Warning::class, $messageBody, $messageCode, $messageArguments, $messageTitle);
83  break;
85  $message = $this->objectManager->get(Error::class, $messageBody, $messageCode, $messageArguments, $messageTitle);
86  break;
87  default:
88  $message = $this->objectManager->get(Message::class, $messageBody, $messageCode, $messageArguments, $messageTitle);
89  break;
90  }
91 
92  $flashMessage = $this->objectManager->get(
93  FlashMessage::class,
94  $message->render(),
95  $message->getTitle(),
96  $severity,
97  true
98  );
99 
100  $this->finisherContext->getControllerContext()->getFlashMessageQueue()->addMessage($flashMessage);
101  }
102 }
‪TYPO3\CMS\Core\Messaging\AbstractMessage
Definition: AbstractMessage.php:24
‪TYPO3\CMS\Extbase\Error\Notice
Definition: Notice.php:22
‪TYPO3\CMS\Form\Domain\Finishers
Definition: AbstractFinisher.php:3
‪TYPO3\CMS\Extbase\Error\Message
Definition: Message.php:21
‪TYPO3\CMS\Form\Domain\Finishers\FlashMessageFinisher
Definition: FlashMessageFinisher.php:48
‪TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING
‪const WARNING
Definition: AbstractMessage.php:28
‪TYPO3\CMS\Form\Domain\Finishers\FlashMessageFinisher\executeInternal
‪executeInternal()
Definition: FlashMessageFinisher.php:66
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher
Definition: AbstractFinisher.php:35
‪TYPO3\CMS\Extbase\Error\Error
Definition: Error.php:22
‪TYPO3\CMS\Form\Domain\Finishers\Exception\FinisherException
Definition: FinisherException.php:24
‪TYPO3\CMS\Extbase\Error\Warning
Definition: Warning.php:22
‪TYPO3\CMS\Core\Messaging\AbstractMessage\OK
‪const OK
Definition: AbstractMessage.php:27
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:22
‪TYPO3\CMS\Form\Domain\Finishers\FlashMessageFinisher\$defaultOptions
‪array $defaultOptions
Definition: FlashMessageFinisher.php:52
‪TYPO3\CMS\Core\Messaging\AbstractMessage\NOTICE
‪const NOTICE
Definition: AbstractMessage.php:25
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher\parseOption
‪string array null parseOption(string $optionName)
Definition: AbstractFinisher.php:155
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:29