[BUGFIX] Extbase must not use legacy flash message handling
authorAlexander Schnitzler <alex.schnitzler@typovision.de>
Sat, 13 Apr 2013 20:43:27 +0000 (22:43 +0200)
committerAlexander Schnitzler <typo3@alexanderschnitzler.de>
Mon, 15 Apr 2013 21:27:35 +0000 (23:27 +0200)
Since the core introduced a new flash message handling the
handling in Extbase has to be adjusted as well.

Also introduces a compat layer.

Releases: 6.1
Resolves: #47196
Change-Id: I4dbee79e9181c5ecbece4549039114f58ea6f33a
Reviewed-on: https://review.typo3.org/19944
Reviewed-by: Alexander Schnitzler
Tested-by: Alexander Schnitzler
typo3/sysext/extbase/Classes/Mvc/Cli/RequestHandler.php
typo3/sysext/extbase/Classes/Mvc/Controller/AbstractController.php
typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php
typo3/sysext/extbase/Classes/Mvc/Controller/ControllerContext.php
typo3/sysext/extbase/Classes/Mvc/Controller/FlashMessageContainer.php
typo3/sysext/extbase/Classes/Mvc/Web/AbstractRequestHandler.php
typo3/sysext/extbase/Tests/Unit/Core/BootstrapTest.php
typo3/sysext/extbase/Tests/Unit/Mvc/Controller/ActionControllerTest.php
typo3/sysext/extbase/ext_typoscript_setup.txt

index 5ed3742..b023c6b 100644 (file)
@@ -47,11 +47,6 @@ class RequestHandler implements \TYPO3\CMS\Extbase\Mvc\RequestHandlerInterface {
        protected $requestBuilder;
 
        /**
-        * @var \TYPO3\CMS\Extbase\Mvc\Controller\FlashMessageContainer
-        */
-       protected $flashMessageContainer;
-
-       /**
         * @var \TYPO3\CMS\Extbase\Service\EnvironmentService
         */
        protected $environmentService;
@@ -65,14 +60,6 @@ class RequestHandler implements \TYPO3\CMS\Extbase\Mvc\RequestHandlerInterface {
        }
 
        /**
-        * @param \TYPO3\CMS\Extbase\Mvc\Controller\FlashMessageContainer $flashMessageContainer
-        * @return void
-        */
-       public function injectFlashMessageContainer(\TYPO3\CMS\Extbase\Mvc\Controller\FlashMessageContainer $flashMessageContainer) {
-               $this->flashMessageContainer = $flashMessageContainer;
-       }
-
-       /**
         * @param \TYPO3\CMS\Extbase\Mvc\Dispatcher $dispatcher
         * @return void
         */
index 8aeaba6..0f6f8b1 100644 (file)
@@ -119,8 +119,14 @@ abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\C
        protected $controllerContext;
 
        /**
-        * The flash messages. Use $this->flashMessageContainer->add(...) to add a new Flash message.
-        *
+        * @return ControllerContext
+        * @api
+        */
+       public function getControllerContext() {
+               return $this->controllerContext;
+       }
+
+       /**
         * @var \TYPO3\CMS\Extbase\Mvc\Controller\FlashMessageContainer
         * @api
         */
@@ -260,6 +266,7 @@ abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\C
         * @api
         */
        protected function buildControllerContext() {
+               /** @var $controllerContext \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext */
                $controllerContext = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerContext');
                $controllerContext->setRequest($this->request);
                $controllerContext->setResponse($this->response);
@@ -270,6 +277,7 @@ abstract class AbstractController implements \TYPO3\CMS\Extbase\Mvc\Controller\C
                        $controllerContext->setArgumentsMappingResults($this->argumentsMappingResults);
                }
                $controllerContext->setUriBuilder($this->uriBuilder);
+
                $controllerContext->setFlashMessageContainer($this->flashMessageContainer);
                return $controllerContext;
        }
index d002d63..4a09e84 100644 (file)
@@ -447,7 +447,7 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                if ($this->configurationManager->isFeatureEnabled('rewrittenPropertyMapper')) {
                        $errorFlashMessage = $this->getErrorFlashMessage();
                        if ($errorFlashMessage !== FALSE) {
-                               $this->flashMessageContainer->add($errorFlashMessage, '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
+                               $this->controllerContext->getFlashMessageQueue()->addMessage(new \TYPO3\CMS\Core\Messaging\FlashMessage($errorFlashMessage, '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR));
                        }
                        $referringRequest = $this->request->getReferringRequest();
                        if ($referringRequest !== NULL) {
@@ -468,7 +468,7 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                        $this->request->setErrors($this->argumentsMappingResults->getErrors());
                        $errorFlashMessage = $this->getErrorFlashMessage();
                        if ($errorFlashMessage !== FALSE) {
-                               $this->flashMessageContainer->add($errorFlashMessage, '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
+                               $this->controllerContext->getFlashMessageQueue()->addMessage(new \TYPO3\CMS\Core\Messaging\FlashMessage($errorFlashMessage, '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR));
                        }
                        $referrer = $this->request->getInternalArgument('__referrer');
                        if ($referrer !== NULL) {
index f7ae744..1c7d0cb 100644 (file)
@@ -67,6 +67,47 @@ class ControllerContext {
        protected $flashMessageContainer;
 
        /**
+        * @var \TYPO3\CMS\Core\Messaging\FlashMessageQueue
+        */
+       protected $flashMessageQueue;
+
+       /**
+        * @var \TYPO3\CMS\Core\Messaging\FlashMessageService
+        */
+       protected $flashMessageService;
+
+       /**
+        * @param \TYPO3\CMS\Core\Messaging\FlashMessageService $flashMessageService
+        */
+       public function injectFlashMessageService(\TYPO3\CMS\Core\Messaging\FlashMessageService $flashMessageService) {
+               $this->flashMessageService = $flashMessageService;
+       }
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
+        */
+       protected $configurationManager;
+
+       /**
+        * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
+        */
+       public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager) {
+               $this->configurationManager = $configurationManager;
+       }
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Service\ExtensionService
+        */
+       protected $extensionService;
+
+       /**
+        * @param \TYPO3\CMS\Extbase\Service\ExtensionService $extensionService
+        */
+       public function injectExtensionService(\TYPO3\CMS\Extbase\Service\ExtensionService $extensionService) {
+               $this->extensionService = $extensionService;
+       }
+
+       /**
         * Set the request of the controller
         *
         * @param \TYPO3\CMS\Extbase\Mvc\Request $request
@@ -168,21 +209,53 @@ class ControllerContext {
         * Set the flash messages
         *
         * @param \TYPO3\CMS\Extbase\Mvc\Controller\FlashMessageContainer $flashMessageContainer
+        * @deprecated since 6.1, will be removed 2 versions later
         * @return void
         */
        public function setFlashMessageContainer(\TYPO3\CMS\Extbase\Mvc\Controller\FlashMessageContainer $flashMessageContainer) {
                $this->flashMessageContainer = $flashMessageContainer;
+               $flashMessageContainer->setControllerContext($this);
        }
 
        /**
         * Get the flash messages
         *
         * @return \TYPO3\CMS\Extbase\Mvc\Controller\FlashMessageContainer
-        * @api
+        * @deprecated since 6.1, will be removed 2 versions later
         */
        public function getFlashMessageContainer() {
+               \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
                return $this->flashMessageContainer;
        }
+
+       /**
+        * @return \TYPO3\CMS\Core\Messaging\FlashMessageQueue
+        * @api
+        */
+       public function getFlashMessageQueue() {
+               if (!$this->flashMessageQueue instanceof \TYPO3\CMS\Core\Messaging\FlashMessageQueue) {
+                       if ($this->useLegacyFlashMessageHandling()) {
+                               $this->flashMessageQueue = $this->flashMessageService->getMessageQueueByIdentifier();
+                       } else {
+                               $this->flashMessageQueue = $this->flashMessageService->getMessageQueueByIdentifier(
+                                       'extbase.flashmessages.' . $this->extensionService->getPluginNamespace($this->request->getControllerExtensionName(), $this->request->getPluginName())
+                               );
+                       }
+               }
+
+               return $this->flashMessageQueue;
+       }
+
+       /**
+        * @deprecated since 6.1, will be removed 2 versions later
+        * @return boolean
+        */
+       public function useLegacyFlashMessageHandling() {
+               return (boolean) \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath(
+                       $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK),
+                       'legacy.enableLegacyFlashMessageHandling'
+               );
+       }
 }
 
 ?>
\ No newline at end of file
index 28d4958..39acc8e 100644 (file)
@@ -37,20 +37,16 @@ namespace TYPO3\CMS\Extbase\Mvc\Controller;
 class FlashMessageContainer implements \TYPO3\CMS\Core\SingletonInterface {
 
        /**
-        * @var \TYPO3\CMS\Core\Messaging\FlashMessageQueue Default queue
+        * @var \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
         */
-       protected $flashMessageQueue = NULL;
+       protected $controllerContext;
 
        /**
-        * Constructor
+        * @param \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext
+        * @deprecated since 6.1, will be removed 2 versions later
         */
-       public function __construct() {
-               /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
-               $flashMessageService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
-                       'TYPO3\\CMS\\Core\\Messaging\\FlashMessageService'
-               );
-               /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
-               $this->flashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
+       public function setControllerContext(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext) {
+               $this->controllerContext = $controllerContext;
        }
 
        /**
@@ -67,9 +63,10 @@ class FlashMessageContainer implements \TYPO3\CMS\Core\SingletonInterface {
         * @param integer $severity optional severity code. One of the \TYPO3\CMS\Core\Messaging\FlashMessage constants
         * @throws \InvalidArgumentException
         * @return void
-        * @api
+        * @deprecated since 6.1, will be removed 2 versions later
         */
        public function add($message, $title = '', $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK) {
+               \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
                if (!is_string($message)) {
                        throw new \InvalidArgumentException(
                                'The flash message must be string, ' . gettype($message) . ' given.',
@@ -80,38 +77,35 @@ class FlashMessageContainer implements \TYPO3\CMS\Core\SingletonInterface {
                $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
                        'TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $message, $title, $severity, TRUE
                );
-               $this->flashMessageQueue->enqueue($flashMessage);
+               $this->controllerContext->getFlashMessageQueue()->addMessage($flashMessage);
        }
 
        /**
-        * Get all flash messages currently available.
-        *
-        * @return array<\TYPO3\CMS\Core\Messaging\FlashMessage> An array of flash messages
-        * @api
+        * @return array An array of flash messages: array<\TYPO3\CMS\Core\Messaging\FlashMessage>
+        * @deprecated since 6.1, will be removed 2 versions later
         */
        public function getAllMessages() {
-               return $this->flashMessageQueue->getAllMessages();
+               \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
+               return $this->controllerContext->getFlashMessageQueue()->getAllMessages();
        }
 
        /**
-        * Reset all flash messages.
-        *
         * @return void
-        * @api
+        * @deprecated since 6.1, will be removed 2 versions later
         */
        public function flush() {
-               $this->flashMessageQueue->getAllMessagesAndFlush();
+               \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
+               $this->controllerContext->getFlashMessageQueue()->getAllMessagesAndFlush();
        }
 
        /**
-        * Get all flash messages currently available. And removes them from the session.
-        *
-        * @return array<\TYPO3\CMS\Core\Messaging\FlashMessage> An array of flash messages
-        * @api
+        * @return array An array of flash messages: array<\TYPO3\CMS\Core\Messaging\FlashMessage>
+        * @deprecated since 6.1, will be removed 2 versions later
         */
        public function getAllMessagesAndFlush() {
-               return $this->flashMessageQueue->getAllMessagesAndFlush();
+               \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
+               return $this->controllerContext->getFlashMessageQueue()->getAllMessagesAndFlush();
        }
 }
 
-?>
+?>
\ No newline at end of file
index 72fdc5f..b353a19 100644 (file)
@@ -48,11 +48,6 @@ abstract class AbstractRequestHandler implements \TYPO3\CMS\Extbase\Mvc\RequestH
        protected $requestBuilder;
 
        /**
-        * @var \TYPO3\CMS\Extbase\Mvc\Controller\FlashMessageContainer
-        */
-       protected $flashMessageContainer;
-
-       /**
         * @var \TYPO3\CMS\Extbase\Service\EnvironmentService
         */
        protected $environmentService;
@@ -66,14 +61,6 @@ abstract class AbstractRequestHandler implements \TYPO3\CMS\Extbase\Mvc\RequestH
        }
 
        /**
-        * @param \TYPO3\CMS\Extbase\Mvc\Controller\FlashMessageContainer $flashMessageContainer
-        * @return void
-        */
-       public function injectFlashMessageContainer(\TYPO3\CMS\Extbase\Mvc\Controller\FlashMessageContainer $flashMessageContainer) {
-               $this->flashMessageContainer = $flashMessageContainer;
-       }
-
-       /**
         * @param \TYPO3\CMS\Extbase\Mvc\Dispatcher $dispatcher
         * @return void
         */
index 21808eb..8d94f5f 100644 (file)
@@ -90,7 +90,6 @@ class BootstrapTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $cliRequestHandler->injectObjectManager($this->objectManager);
                $cliRequestHandler->injectRequestBuilder($this->objectManager->get('TYPO3\CMS\Extbase\Mvc\Cli\RequestBuilder'));
                $cliRequestHandler->injectDispatcher($this->objectManager->get('TYPO3\CMS\Extbase\Mvc\Dispatcher'));
-               $cliRequestHandler->injectFlashMessageContainer($this->objectManager->get('TYPO3\CMS\Extbase\Mvc\Controller\FlashMessageContainer'));
 
                /** @var $cliResponse \TYPO3\CMS\Extbase\Mvc\Cli\Response */
                $cliResponse = $this->getMock('TYPO3\CMS\Extbase\Mvc\Cli\Response', array('send'));
index 6150008..f936fba 100644 (file)
@@ -478,15 +478,17 @@ class ActionControllerTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         */
        public function defaultErrorActionSetsArgumentMappingResultsErrorsInRequest() {
                $mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Request', array(), array(), '', FALSE);
-               $mockFlashMessageContainer = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\FlashMessageContainer', array(), array(), '', FALSE);
                $mockError = $this->getMock('TYPO3\\CMS\\Extbase\\Error\\Error', array('getMessage'), array(), '', FALSE);
                $mockArgumentsMappingResults = $this->getMock('TYPO3\\CMS\\Extbase\\Property\\MappingResults', array('getErrors', 'getWarnings'), array(), '', FALSE);
                $mockArgumentsMappingResults->expects($this->atLeastOnce())->method('getErrors')->will($this->returnValue(array($mockError)));
                $mockArgumentsMappingResults->expects($this->any())->method('getWarnings')->will($this->returnValue(array()));
-               $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('pushFlashMessage', 'clearCacheOnError'), array(), '', FALSE);
+               /** @var $mockController \TYPO3\CMS\Extbase\Mvc\Controller\ActionController|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('clearCacheOnError'), array(), '', FALSE);
+               $controllerContext = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerContext', array('getFlashMessageQueue'));
+               $controllerContext->expects($this->any())->method('getFlashMessageQueue')->will($this->returnValue(new \TYPO3\CMS\Core\Messaging\FlashMessageQueue('foo')));
                $this->enableDeprecatedPropertyMapperInController($mockController);
+               $mockController->_set('controllerContext', $controllerContext);
                $mockController->_set('request', $mockRequest);
-               $mockController->_set('flashMessageContainer', $mockFlashMessageContainer);
                $mockController->_set('argumentsMappingResults', $mockArgumentsMappingResults);
                $mockRequest->expects($this->once())->method('setErrors')->with(array($mockError));
                $mockController->_call('errorAction');
@@ -578,4 +580,4 @@ class ActionControllerTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        }
 }
 
-?>
+?>
\ No newline at end of file
index aefbcb4..75b59f7 100644 (file)
@@ -100,4 +100,7 @@ config.tx_extbase {
                # if set to 1, the enable fields are ignored in BE context
                ignoreAllEnableFieldsInBe = 0
        }
+       legacy {
+               enableLegacyFlashMessageHandling = 1
+       }
 }