[BUGFIX] TSFE->altPageTitle can not be set in extensions 35/27135/4
authorMarkus Klein <klein.t3@mfc-linz.at>
Mon, 13 Jan 2014 10:03:42 +0000 (11:03 +0100)
committerMarkus Klein <klein.t3@mfc-linz.at>
Mon, 3 Feb 2014 13:07:59 +0000 (14:07 +0100)
It is not possible to set $GLOBALS['TSFE']->altPageTitle
in USER_INT extensions anymore to modify the page title.

This has been possible before in the 4.x branches.

Fix this by implementing the title generation like all
other header data.

Resolves: #54467
Releases: 6.2, 6.1
Change-Id: I3d5be34b95cb295b92732d2f2f9bd1f123812365
Reviewed-on: https://review.typo3.org/27135
Tested-by: Alexander Opitz
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/core/Classes/Page/PageRenderer.php
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
typo3/sysext/frontend/Classes/Page/PageGenerator.php
typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php

index 5b2ac64..ad07776 100644 (file)
@@ -1907,7 +1907,9 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface {
        public function renderJavaScriptAndCssForProcessingOfUncachedContentObjects($cachedPageContent, $substituteHash) {
                $this->prepareRendering();
                list($jsLibs, $jsFiles, $jsFooterFiles, $cssFiles, $jsInline, $cssInline, $jsFooterInline, $jsFooterLibs) = $this->renderJavaScriptAndCss();
+               $title = $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '';
                $markerArray = array(
+                       '<!-- ###TITLE' . $substituteHash . '### -->' => $title,
                        '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->' => $cssFiles,
                        '<!-- ###CSS_INLINE' . $substituteHash . '### -->' => $cssInline,
                        '<!-- ###JS_INLINE' . $substituteHash . '### -->' => $jsInline,
@@ -2035,9 +2037,9 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface {
                        'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
                        'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
                        'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
-                       'TITLE' => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
                        'META' => implode(LF, $this->metaTags),
                        'BODY' => $this->bodyContent,
+                       'TITLE' => '<!-- ###TITLE' . $substituteHash . '### -->',
                        'CSS_INCLUDE' => '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->',
                        'CSS_INLINE' => '<!-- ###CSS_INLINE' . $substituteHash . '### -->',
                        'JS_INLINE' => '<!-- ###JS_INLINE' . $substituteHash . '### -->',
index 0948c9e..a2b4ac6 100644 (file)
@@ -3393,6 +3393,15 @@ class TypoScriptFrontendController {
        }
 
        /**
+        * Generate the page title again as TSFE->altPageTitle might have been modified by an inc script
+        *
+        * @return void
+        */
+       protected function regeneratePageTitle() {
+               \TYPO3\CMS\Frontend\Page\PageGenerator::generatePageTitle();
+       }
+
+       /**
         * Processes the INTinclude-scripts
         *
         * @return void
@@ -3413,10 +3422,14 @@ class TypoScriptFrontendController {
                $this->recursivelyReplaceIntPlaceholdersInContent();
                $GLOBALS['TT']->push('Substitute header section');
                $this->INTincScript_loadJSCode();
+
+               $this->regeneratePageTitle();
+
                $this->content = $this->getPageRenderer()->renderJavaScriptAndCssForProcessingOfUncachedContentObjects($this->content, $this->config['INTincScript_ext']['divKey']);
                $this->content = str_replace('<!--HD_' . $this->config['INTincScript_ext']['divKey'] . '-->', $this->convOutputCharset(implode(LF, $this->additionalHeaderData), 'HD'), $this->content);
                $this->content = str_replace('<!--FD_' . $this->config['INTincScript_ext']['divKey'] . '-->', $this->convOutputCharset(implode(LF, $this->additionalFooterData), 'FD'), $this->content);
                $this->content = str_replace('<!--TDS_' . $this->config['INTincScript_ext']['divKey'] . '-->', $this->convOutputCharset($this->divSection, 'TDS'), $this->content);
+
                // Replace again, because header and footer data and page renderer replacements may introduce additional placeholders (see #44825)
                $this->recursivelyReplaceIntPlaceholdersInContent();
                $this->setAbsRefPrefix();
index 0bda6c4..19e415c 100644 (file)
@@ -46,6 +46,12 @@ namespace TYPO3\CMS\Frontend\Page;
 class PageGenerator {
 
        /**
+        * Do not render title tag
+        * Typoscript setting: [config][noPageTitle]
+        */
+       const NO_PAGE_TITLE = 2;
+
+       /**
         * Setting some vars in TSFE, primarily based on TypoScript config settings.
         *
         * @return void
@@ -666,14 +672,7 @@ class PageGenerator {
                if (is_array($GLOBALS['TSFE']->pSetup['footerData.'])) {
                        $pageRenderer->addFooterData($GLOBALS['TSFE']->cObj->cObjGet($GLOBALS['TSFE']->pSetup['footerData.'], 'footerData.'));
                }
-               // Title
-               $titleTagContent = $GLOBALS['TSFE']->tmpl->printTitle($GLOBALS['TSFE']->altPageTitle ? $GLOBALS['TSFE']->altPageTitle : $GLOBALS['TSFE']->page['title'], $GLOBALS['TSFE']->config['config']['noPageTitle'], $GLOBALS['TSFE']->config['config']['pageTitleFirst']);
-               if ($GLOBALS['TSFE']->config['config']['titleTagFunction']) {
-                       $titleTagContent = $GLOBALS['TSFE']->cObj->callUserFunction($GLOBALS['TSFE']->config['config']['titleTagFunction'], array(), $titleTagContent);
-               }
-               if (strlen($titleTagContent) && intval($GLOBALS['TSFE']->config['config']['noPageTitle']) !== 2) {
-                       $pageRenderer->setTitle($titleTagContent);
-               }
+               static::generatePageTitle();
                // Add ending slash only to documents rendered as xhtml
                $endingSlash = $GLOBALS['TSFE']->xhtmlVersion ? ' /' : '';
                $pageRenderer->addMetaTag('<meta name="generator" content="TYPO3 ' . TYPO3_branch . ' CMS"' . $endingSlash . '>');
@@ -1023,6 +1022,31 @@ class PageGenerator {
                return $OK;
        }
 
+       /**
+        * Generate title for page.
+        * Takes the settings ['config']['noPageTitle'], ['config']['pageTitleFirst'], ['config']['titleTagFunction']
+        * and ['config']['noPageTitle'] into account.
+        * Furthermore $GLOBALS['TSFE']->altPageTitle is observed.
+        *
+        * @return void
+        */
+       static public function generatePageTitle() {
+               $titleTagContent = $GLOBALS['TSFE']->tmpl->printTitle(
+                       $GLOBALS['TSFE']->altPageTitle ? $GLOBALS['TSFE']->altPageTitle : $GLOBALS['TSFE']->page['title'],
+                       $GLOBALS['TSFE']->config['config']['noPageTitle'],
+                       $GLOBALS['TSFE']->config['config']['pageTitleFirst']
+               );
+               if ($GLOBALS['TSFE']->config['config']['titleTagFunction']) {
+                       $titleTagContent = $GLOBALS['TSFE']->cObj->callUserFunction(
+                               $GLOBALS['TSFE']->config['config']['titleTagFunction'],
+                               array(),
+                               $titleTagContent
+                       );
+               }
+               if ($titleTagContent !== '' && (integer)$GLOBALS['TSFE']->config['config']['noPageTitle'] !== self::NO_PAGE_TITLE) {
+                       $GLOBALS['TSFE']->getPageRenderer()->setTitle($titleTagContent);
+               }
+       }
 }
 
 
index 48d1efe..3985995 100644 (file)
@@ -78,7 +78,8 @@ class TypoScriptFrontendControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCas
                        'INTincScript_process',
                        'INTincScript_includeLibs',
                        'INTincScript_loadJSCode',
-                       'setAbsRefPrefix'
+                       'setAbsRefPrefix',
+                   'regeneratePageTitle'
                ), array(), '', FALSE);
                $tsfe->expects($this->exactly(2))->method('INTincScript_process')->will($this->returnCallback(array($this, 'INTincScript_processCallback')));
                $tsfe->content = file_get_contents(__DIR__ . '/Fixtures/renderedPage.html');