Added feature #16026: Added hook / Cannot hook into the marker replacement functional...
authorBenni Mack <benni.mack@typo3.org>
Sun, 17 Oct 2010 09:59:13 +0000 (09:59 +0000)
committerBenni Mack <benni.mack@typo3.org>
Sun, 17 Oct 2010 09:59:13 +0000 (09:59 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@9123 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/template.php

index abdfdc0..c46be21 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,7 @@
 
 2010-10-17  Benjamin Mack  <benni@typo3.org>
 
+       * Added feature #16026: Added hook / Cannot hook into the marker replacement functionality for BE templates
        * Fixed bug #16020: Streamline usage of template.php:dynTabMenu
        * Fixed bug #16022: Size calculation function can only deal with integers
        * Fixed bug #16006: Remove the checkbox that clears the input fields in TCE-forms and replace it with a sprite icon (Thanks to Jo Hasenau)
index 03b6e53..7811060 100644 (file)
@@ -169,6 +169,7 @@ class template {
        var $postCode='';                               // Additional 'page-end' code could be accommulated in this var. It will be outputted at the end of page before </body> and some other internal page-end code.
        var $docType = '';                              // Doc-type used in the header. Default is xhtml_trans. You can also set it to 'html_3', 'xhtml_strict' or 'xhtml_frames'.
        var $moduleTemplate = '';               // HTML template with markers for module
+       protected $moduleTemplateFilename = ''; // the base file (not overlaid by TBE_STYLES) for the current module, useful for hooks when finding out which modules is rendered currently
 
                // Other vars you can change, but less frequently used:
        var $scriptID='';                               // Script ID.
@@ -2057,6 +2058,9 @@ $str.=$this->docBodyTagBegin().
         * @return      string          HTML of template
         */
        function getHtmlTemplate($filename)     {
+                       // setting the name of the original HTML template
+               $this->moduleTemplateFilename = $filename;
+
                if ($GLOBALS['TBE_STYLES']['htmlTemplates'][$filename]) {
                        $filename = $GLOBALS['TBE_STYLES']['htmlTemplates'][$filename];
                }
@@ -2079,7 +2083,7 @@ $str.=$this->docBodyTagBegin().
         *
         * @param       string          filename
         */
-       function setModuleTemplate($filename) {
+       public function setModuleTemplate($filename) {
                        // Load Prototype lib for IE event
                $this->pageRenderer->loadPrototype();
                $this->loadJavascriptLib('js/iecompatibility.js');
@@ -2128,27 +2132,35 @@ $str.=$this->docBodyTagBegin().
                        $moduleBody = t3lib_parsehtml::substituteSubpart($moduleBody, $marker, $content);
                }
 
+                       // adding flash messages
                if ($this->showFlashMessages) {
-                               // adding flash messages
                        $flashMessages = t3lib_FlashMessageQueue::renderFlashMessages();
                        if (!empty($flashMessages)) {
-                               $flashMessages = '<div id="typo3-messages">' . $flashMessages . '</div>';
+                               $markerArray['FLASHMESSAGES'] = '<div id="typo3-messages">' . $flashMessages . '</div>';
+
+                                       // if there is no dedicated marker for the messages present
+                                       // then force them to appear before the content
+                               if (strpos($moduleBody, '###FLASHMESSAGES###') === FALSE) {
+                                       $moduleBody = str_replace(
+                                               '###CONTENT###',
+                                               '###FLASHMESSAGES######CONTENT###',
+                                               $moduleBody
+                                       );
+                               }
                        }
+               }
 
-                       if (strstr($moduleBody, '###FLASHMESSAGES###')) {
-                                       // either replace a dedicated marker for the messages if present
-                               $moduleBody = str_replace(
-                                       '###FLASHMESSAGES###',
-                                       $flashMessages,
-                                       $moduleBody
-                               );
-                       } else {
-                                       // or force them to appear before the content
-                               $moduleBody = str_replace(
-                                       '###CONTENT###',
-                                       $flashMessages . '###CONTENT###',
-                                       $moduleBody
-                               );
+                       // Hook for adding more markers/content to the page, like the version selector
+               if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['moduleBodyPostProcess'])) {
+                       $params = array(
+                               'moduleTemplateFilename' => &$this->moduleTemplateFilename,
+                               'moduleTemplate' => &$this->moduleTemplate,
+                               'moduleBody' => &$moduleBody,
+                               'markers' => &$markerArray,
+                               'parentObject' => &$this
+                       );
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['moduleBodyPostProcess'] as $funcRef) {
+                               t3lib_div::callUserFunction($funcRef, $params, $this);
                        }
                }