‪TYPO3CMS  10.4
FlashMessageFinisher.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 
18 /*
19  * Inspired by and partially taken from the Neos.Form package (www.neos.io)
20  */
21 
23 
31 
52 {
53 
57  protected ‪$defaultOptions = [
58  'messageBody' => null,
59  'messageTitle' => '',
60  'messageArguments' => [],
61  'messageCode' => null,
62  'severity' => ‪AbstractMessage::OK,
63  ];
64 
71  protected function ‪executeInternal()
72  {
73  $messageBody = $this->‪parseOption('messageBody');
74  if (!is_string($messageBody)) {
75  throw new ‪FinisherException(sprintf('The message body must be of type string, "%s" given.', gettype($messageBody)), 1335980069);
76  }
77  $messageTitle = $this->‪parseOption('messageTitle');
78  $messageArguments = $this->‪parseOption('messageArguments');
79  $messageCode = $this->‪parseOption('messageCode');
80  $severity = $this->‪parseOption('severity');
81  switch ($severity) {
83  $message = $this->objectManager->get(Notice::class, $messageBody, $messageCode, $messageArguments, $messageTitle);
84  break;
86  $message = $this->objectManager->get(Warning::class, $messageBody, $messageCode, $messageArguments, $messageTitle);
87  break;
89  $message = $this->objectManager->get(Error::class, $messageBody, $messageCode, $messageArguments, $messageTitle);
90  break;
91  default:
92  $message = $this->objectManager->get(Message::class, $messageBody, $messageCode, $messageArguments, $messageTitle);
93  break;
94  }
95 
96  $flashMessage = $this->objectManager->get(
97  FlashMessage::class,
98  $message->render(),
99  $message->getTitle(),
100  $severity,
101  true
102  );
103 
104  $this->finisherContext->getControllerContext()->getFlashMessageQueue()->addMessage($flashMessage);
105  }
106 }
‪TYPO3\CMS\Core\Messaging\AbstractMessage
Definition: AbstractMessage.php:26
‪TYPO3\CMS\Extbase\Error\Notice
Definition: Notice.php:25
‪TYPO3\CMS\Form\Domain\Finishers
Definition: AbstractFinisher.php:22
‪TYPO3\CMS\Extbase\Error\Message
Definition: Message.php:24
‪TYPO3\CMS\Form\Domain\Finishers\FlashMessageFinisher
Definition: FlashMessageFinisher.php:52
‪TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING
‪const WARNING
Definition: AbstractMessage.php:30
‪TYPO3\CMS\Form\Domain\Finishers\FlashMessageFinisher\executeInternal
‪executeInternal()
Definition: FlashMessageFinisher.php:70
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher
Definition: AbstractFinisher.php:41
‪TYPO3\CMS\Extbase\Error\Error
Definition: Error.php:25
‪TYPO3\CMS\Form\Domain\Finishers\Exception\FinisherException
Definition: FinisherException.php:26
‪TYPO3\CMS\Extbase\Error\Warning
Definition: Warning.php:25
‪TYPO3\CMS\Core\Messaging\AbstractMessage\OK
‪const OK
Definition: AbstractMessage.php:29
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪TYPO3\CMS\Form\Domain\Finishers\FlashMessageFinisher\$defaultOptions
‪array $defaultOptions
Definition: FlashMessageFinisher.php:56
‪TYPO3\CMS\Core\Messaging\AbstractMessage\NOTICE
‪const NOTICE
Definition: AbstractMessage.php:27
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher\parseOption
‪string array null parseOption(string $optionName)
Definition: AbstractFinisher.php:161
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31