Feature #7098 » flashmessages_v2.patch
extbase/Classes/MVC/Controller/FlashMessage.php (revision 0) | ||
---|---|---|
<?php
|
||
/***************************************************************
|
||
* Copyright notice
|
||
*
|
||
* (c) 2009 Dennis Ahrens <dennis.ahrens@fh-hannover.de>
|
||
* 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;
|
||
}
|
||
}
|
||
?>
|
extbase/Classes/MVC/Controller/FlashMessages.php (working copy) | ||
---|---|---|
/**
|
||
* The array of flash messages
|
||
* @var array<string>
|
||
* @var array<Tx_Extbase_MVC_Controller_FlashMessage>
|
||
*/
|
||
protected $flashMessages = array();
|
||
... | ... | |
/**
|
||
* 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));
|
||
}
|
||
/**
|
extbase/ext_autoload.php (working copy) | ||
---|---|---|
'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',
|
fluid/Classes/ViewHelpers/FlashMessagesViewHelper.php (working copy) | ||
---|---|---|
if (count($flashMessages) > 0) {
|
||
$tagContent = '';
|
||
foreach ($flashMessages as $singleFlashMessage) {
|
||
$tagContent .= '<li>' . htmlspecialchars($singleFlashMessage) . '</li>';
|
||
$tagContent .= '<li class="'. $singleFlashMessage->getType() .'">' . htmlspecialchars($singleFlashMessage->getMessage()) . '</li>';
|
||
}
|
||
$this->tag->setContent($tagContent);
|
||
return $this->tag->render();
|