Add a flash message object.
public addMessage ( Neos\Error\Messages\Message $message ) : void | ||
$message | Neos\Error\Messages\Message | |
리턴 | void |
/** * Executes this finisher * @see AbstractFinisher::execute() * * @return void * @throws \Neos\Form\Exception\FinisherException */ protected function executeInternal() { $messageBody = $this->parseOption('messageBody'); if (!is_string($messageBody)) { throw new \Neos\Form\Exception\FinisherException(sprintf('The message body must be of type string, "%s" given.', gettype($messageBody)), 1335980069); } $messageTitle = $this->parseOption('messageTitle'); $messageArguments = $this->parseOption('messageArguments'); $messageCode = $this->parseOption('messageCode'); $severity = $this->parseOption('severity'); switch ($severity) { case Message::SEVERITY_NOTICE: $message = new \Neos\Error\Messages\Notice($messageBody, $messageCode, $messageArguments, $messageTitle); break; case Message::SEVERITY_WARNING: $message = new \Neos\Error\Messages\Warning($messageBody, $messageCode, $messageArguments, $messageTitle); break; case Message::SEVERITY_ERROR: $message = new \Neos\Error\Messages\Error($messageBody, $messageCode, $messageArguments, $messageTitle); break; default: $message = new Message($messageBody, $messageCode, $messageArguments, $messageTitle); break; } $this->flashMessageContainer->addMessage($message); }
/** * @test */ public function getMessagesAndFlushCanAlsoFilterBySeverity() { $messages = [0 => new FlowError\Notice('This is a test message', 1), 1 => new FlowError\Warning('This is another test message', 2)]; $this->flashMessageContainer->addMessage($messages[0]); $this->flashMessageContainer->addMessage($messages[1]); $filteredFlashMessages = $this->flashMessageContainer->getMessagesAndFlush(FlowError\Message::SEVERITY_NOTICE); $this->assertEquals(count($filteredFlashMessages), 1); reset($filteredFlashMessages); $flashMessage = current($filteredFlashMessages); $this->assertEquals($messages[0], $flashMessage); $this->assertEquals([], $this->flashMessageContainer->getMessages(FlowError\Message::SEVERITY_NOTICE)); $this->assertEquals([$messages[1]], array_values($this->flashMessageContainer->getMessages())); }
/** * If Site Packages already exist and are active, we will deactivate them in order to prevent * interactions with the newly created or imported package (like Content Dimensions being used). * * @param string $packageKey * @return array */ protected function deactivateOtherSitePackages($packageKey) { $sitePackagesToDeactivate = $this->packageManager->getFilteredPackages('active', null, 'neos-site'); $deactivatedSitePackages = array(); foreach ($sitePackagesToDeactivate as $sitePackageToDeactivate) { if ($sitePackageToDeactivate->getPackageKey() !== $packageKey) { $this->packageManager->deactivatePackage($sitePackageToDeactivate->getPackageKey()); $deactivatedSitePackages[] = $sitePackageToDeactivate->getPackageKey(); } } if (count($deactivatedSitePackages) >= 1) { $this->flashMessageContainer->addMessage(new Message(sprintf('The existing Site Packages "%s" were deactivated, in order to prevent interactions with the newly created package "%s".', implode(', ', $deactivatedSitePackages), $packageKey))); } }
/** * Creates a Message object and adds it to the FlashMessageContainer. * * This method should be used to add FlashMessages rather than interacting with the container directly. * * @param string $messageBody text of the FlashMessage * @param string $messageTitle optional header of the FlashMessage * @param string $severity severity of the FlashMessage (one of the Message::SEVERITY_* constants) * @param array $messageArguments arguments to be passed to the FlashMessage * @param integer $messageCode * @return void * @throws \InvalidArgumentException if the message body is no string * @see Error\Message * @api */ public function addFlashMessage($messageBody, $messageTitle = '', $severity = Error\Message::SEVERITY_OK, array $messageArguments = [], $messageCode = null) { if (!is_string($messageBody)) { throw new \InvalidArgumentException('The message body must be of type string, "' . gettype($messageBody) . '" given.', 1243258395); } switch ($severity) { case Error\Message::SEVERITY_NOTICE: $message = new Error\Notice($messageBody, $messageCode, $messageArguments, $messageTitle); break; case Error\Message::SEVERITY_WARNING: $message = new Error\Warning($messageBody, $messageCode, $messageArguments, $messageTitle); break; case Error\Message::SEVERITY_ERROR: $message = new Error\Error($messageBody, $messageCode, $messageArguments, $messageTitle); break; default: $message = new Error\Message($messageBody, $messageCode, $messageArguments, $messageTitle); break; } $this->flashMessageContainer->addMessage($message); }