[+BUGFIX] disable cache when displaying FlashMessages in frontend
authorClaus Due <claus@wildside.dk>
Mon, 16 May 2011 21:23:31 +0000 (23:23 +0200)
committerBastian Waidelich <bastian@typo3.org>
Tue, 6 Sep 2011 19:48:04 +0000 (21:48 +0200)
This resolves #5297 by making the FlashMessage
ViewHelper disable the page cache to prevent caching rendered
FlashMessage-HTML in a cacheable controller action which uses
FlashMessages.

Change-Id: I2eeb615625442d9040a0bb21b9e231e224dcba86
Fixes: #5297

typo3/sysext/fluid/Classes/ViewHelpers/FlashMessagesViewHelper.php

index 75ef50d..90d394f 100644 (file)
@@ -68,6 +68,25 @@ class Tx_Fluid_ViewHelpers_FlashMessagesViewHelper extends Tx_Fluid_Core_ViewHel
        const RENDER_MODE_DIV = 'div';
 
        /**
+        * @var tslib_cObj
+        */
+       protected $contentObject;
+
+       /**
+        * @var Tx_Extbase_Configuration_ConfigurationManagerInterface
+        */
+       protected $configurationManager;
+
+       /**
+        * @param Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager
+        * @return void
+        */
+       public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager) {
+               $this->configurationManager = $configurationManager;
+               $this->contentObject = $this->configurationManager->getContentObject();
+       }
+
+       /**
         * Initialize arguments
         *
         * @return void
@@ -79,11 +98,13 @@ class Tx_Fluid_ViewHelpers_FlashMessagesViewHelper extends Tx_Fluid_Core_ViewHel
        }
 
        /**
-        * Render method.
+        * Renders FlashMessages and flushes the FlashMessage queue
+        * Note: This disables the current page cache in order to prevent FlashMessage output
+        * from being cached.
+        * @see tslib_fe::no_cache
         *
         * @param string $renderMode one of the RENDER_MODE_* constants
         * @return string rendered Flash Messages, if there are any.
-        * @author Sebastian Kurf├╝rst <sebastian@typo3.org>
         * @api
         */
        public function render($renderMode = self::RENDER_MODE_UL) {
@@ -91,6 +112,10 @@ class Tx_Fluid_ViewHelpers_FlashMessagesViewHelper extends Tx_Fluid_Core_ViewHel
                if ($flashMessages === NULL || count($flashMessages) === 0) {
                        return '';
                }
+               if (isset($GLOBALS['TSFE']) && $this->contentObject->getUserObjectType() === tslib_cObj::OBJECTTYPE_USER) {
+                       $GLOBALS['TSFE']->no_cache = 1;
+               }
+
                switch ($renderMode) {
                        case self::RENDER_MODE_UL:
                                return $this->renderUl($flashMessages);