Index: extbase/Classes/MVC/Controller/FlashMessage.php =================================================================== --- extbase/Classes/MVC/Controller/FlashMessage.php (revision 0) +++ extbase/Classes/MVC/Controller/FlashMessage.php (revision 0) @@ -0,0 +1,136 @@ + +* All rights reserved +* +* This class is a backport of the corresponding class of FLOW3. +* All credits go to the v5 team. +* +* This script is part of the TYPO3 project. The TYPO3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + +/** + * A FlashMessage. + * + * @version $Id$ + * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later + * @api + */ +class Tx_Extbase_MVC_Controller_FlashMessage { + + /** + * Constants for message types + */ + const NOTICE = 'notice'; + const INFO = 'info'; + const OK = 'ok'; + const WARNING = 'warning'; + const ERROR = 'error'; + + /** + * @var string + */ + protected $message; + + /** + * @var string + */ + protected $type; + + /** + * @var DateTime + */ + protected $time; + + /** + * Default constructor + * + * @param string $message + * @param string $type + */ + public function __construct($message, $type = Tx_Extbase_MVC_Controller_FlashMessage::NOTICE) { + $this->message = $message; + $this->setType($type); + $this->time = new DateTime(); + } + + /** + * Sets the message. + * + * @param string $message + * @return void + */ + public function setMessage($message) { + $this->message = $message; + } + + /** + * Gets the message. + * + * @return string + */ + public function getMessage() { + return $this->message; + } + + /** + * Sets the type. + * The setter is used to realize the enumeration. Only the as constants + * defined values are accepted. + * + * @param string $type + * @throws Tx_Extbase_MVC_Exception_InvalidArgumentValue + * @return void + */ + public function setType($type) { + if ($type === self::NOTICE || + $type === self::INFO || + $type === self::OK || + $type === self::WARNING || + $type === self::ERROR) { + $this->type = $type; + } else { + throw new Tx_Extbase_MVC_Exception_InvalidArgumentValue('FlashMessage type has to be a valid string value related to a known message type', 1276871212); + } + } + + /** + * Gets the type of the message + * + * @return string + */ + public function getType() { + return $this->type; + } + + /** + * Gets the DateTime object indicating when this message was created. + * + * @return DateTime + */ + public function getTime() { + return $this->time; + } + + public function __toString() { + return $this->message; + } + +} +?> \ No newline at end of file Index: extbase/Classes/MVC/Controller/FlashMessages.php =================================================================== --- extbase/Classes/MVC/Controller/FlashMessages.php (revision 2527) +++ extbase/Classes/MVC/Controller/FlashMessages.php (working copy) @@ -39,7 +39,7 @@ /** * The array of flash messages - * @var array + * @var array */ protected $flashMessages = array(); @@ -60,14 +60,17 @@ /** * Add another flash message. * - * @param string $message + * @param string $message The message string. + * @param string $type Use constants definied in Tx_Extbase_MVC_Controller_FlashMessage to set the value. Default: Tx_Extbase_MVC_Controller_FlashMessage::NOTICE * @return void * @api */ - public function add($message) { + public function add($message, $type = Tx_Extbase_MVC_Controller_FlashMessage::NOTICE) { if (!is_string($message)) throw new InvalidArgumentException('The flash message must be string, ' . gettype($message) . ' given.', 1243258395); $this->initialize(); - $this->flashMessages[] = $message; + $flashMessage = t3lib_div::makeInstance('Tx_Extbase_MVC_Controller_FlashMessage', $message, $type); + $this->flashMessages[] = $flashMessage; + file_put_contents(PATH_site.'typo3conf/ext/log.txt', var_export($this->flashMessages, true)); } /** Index: extbase/ext_autoload.php =================================================================== --- extbase/ext_autoload.php (revision 2527) +++ extbase/ext_autoload.php (working copy) @@ -40,6 +40,7 @@ 'tx_extbase_mvc_controller_argumentsvalidator' => $extensionClassesPath . 'MVC/Controller/ArgumentsValidator.php', 'tx_extbase_mvc_controller_controllercontext' => $extensionClassesPath . 'MVC/Controller/ControllerContext.php', 'tx_extbase_mvc_controller_controllerinterface' => $extensionClassesPath . 'MVC/Controller/ControllerInterface.php', + 'tx_extbase_mvc_controller_flashmessage' => $extensionClassesPath . 'MVC/Controller/FlashMessage.php', 'tx_extbase_mvc_controller_flashmessages' => $extensionClassesPath . 'MVC/Controller/FlashMessages.php', 'tx_extbase_mvc_exception_infiniteloop' => $extensionClassesPath . 'MVC/Exception/InfiniteLoop.php', 'tx_extbase_mvc_exception_invalidactionname' => $extensionClassesPath . 'MVC/Exception/InvalidActionName.php', Index: fluid/Classes/ViewHelpers/FlashMessagesViewHelper.php =================================================================== --- fluid/Classes/ViewHelpers/FlashMessagesViewHelper.php (revision 2527) +++ fluid/Classes/ViewHelpers/FlashMessagesViewHelper.php (working copy) @@ -79,7 +79,7 @@ if (count($flashMessages) > 0) { $tagContent = ''; foreach ($flashMessages as $singleFlashMessage) { - $tagContent .= '
  • ' . htmlspecialchars($singleFlashMessage) . '
  • '; + $tagContent .= '
  • ' . htmlspecialchars($singleFlashMessage->getMessage()) . '
  • '; } $this->tag->setContent($tagContent); return $this->tag->render();