[BUGFIX] Allow page.config.pageTitleSeparator 50/35750/4
authorBenjamin Mack <benni@typo3.org>
Sat, 3 Jan 2015 10:22:57 +0000 (11:22 +0100)
committerBenjamin Mack <benni@typo3.org>
Thu, 8 Jan 2015 14:14:32 +0000 (15:14 +0100)
The TypoScript option page.config.pageTitleSeparator
does not work currently, however the unspecific option
config.pageTitleSeparator does work.

This is due to the fact that the PageGenerator class
is preparing all options with TSFE->config and the
TemplateService class is putting everything together
with tmpl->setup which is not the consolidated config
data for this page. In order to streamline the code,
the pageTitleSeparator logic is moved
to PageGenerator where TSFE->config is used instead.

Resolves: #54410
Releases: master, 6.2
Change-Id: I677a852f6a94ea9737dade6e32e19f8b86dc9c89
Reviewed-on: http://review.typo3.org/35750
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benjamin Mack <benni@typo3.org>
Tested-by: Benjamin Mack <benni@typo3.org>
typo3/sysext/core/Classes/TypoScript/TemplateService.php
typo3/sysext/frontend/Classes/Page/PageGenerator.php

index 378139f..f2b0c03 100644 (file)
@@ -1269,29 +1269,24 @@ class TemplateService {
         * @param string $pageTitle The input title string, typically the "title" field of a page's record.
         * @param bool $noTitle If set, then only the site title is outputted (from $this->setup['sitetitle'])
         * @param bool $showTitleFirst If set, then "sitetitle" and $title is swapped
+        * @param string $pageTitleSeparator an alternative to the ": " as the separator between site title and page title
         * @return string The page title on the form "[sitetitle]: [input-title]". Not htmlspecialchar()'ed.
         * @see \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::tempPageCacheContent(), \TYPO3\CMS\Frontend\Page\PageGenerator::renderContentWithHeader()
         */
-       public function printTitle($pageTitle, $noTitle = FALSE, $showTitleFirst = FALSE) {
+       public function printTitle($pageTitle, $noTitle = FALSE, $showTitleFirst = FALSE, $pageTitleSeparator = '') {
                $siteTitle = trim($this->setup['sitetitle']);
                $pageTitle = $noTitle ? '' : $pageTitle;
-               $pageTitleSeparator = '';
                if ($showTitleFirst) {
                        $temp = $siteTitle;
                        $siteTitle = $pageTitle;
                        $pageTitle = $temp;
                }
-               if ($pageTitle != '' && $siteTitle != '') {
+               // only show a separator if there are both site title and page title
+               if ($pageTitle === '' || $siteTitle === '') {
+                       $pageTitleSeparator = '';
+               // use the default separator if non given
+               } elseif (empty($pageTitleSeparator)) {
                        $pageTitleSeparator = ': ';
-                       if (isset($this->setup['config.']['pageTitleSeparator']) && $this->setup['config.']['pageTitleSeparator']) {
-                               $pageTitleSeparator = $this->setup['config.']['pageTitleSeparator'];
-
-                               if (is_object($GLOBALS['TSFE']->cObj) && isset($this->setup['config.']['pageTitleSeparator.']) && is_array($this->setup['config.']['pageTitleSeparator.'])) {
-                                       $pageTitleSeparator = $GLOBALS['TSFE']->cObj->stdWrap($pageTitleSeparator, $this->setup['config.']['pageTitleSeparator.']);
-                               } else {
-                                       $pageTitleSeparator .= ' ';
-                               }
-                       }
                }
                return $siteTitle . $pageTitleSeparator . $pageTitle;
        }
index 0f4d2ab..45b15d6 100644 (file)
@@ -1105,16 +1105,30 @@ class PageGenerator {
        /**
         * Generate title for page.
         * Takes the settings [config][noPageTitle], [config][pageTitleFirst], [config][titleTagFunction]
-        * and [config][pageTitle] as stdWrap into account.
-        * Furthermore $GLOBALS['TSFE']->altPageTitle is observed.
+        * [config][pageTitleSeparator] and [config][noPageTitle] into account.
+        * Furthermore $GLOBALS[TSFE]->altPageTitle is observed.
         *
         * @return void
         */
        static public function generatePageTitle() {
+               $pageTitleSeparator = '';
+
+               // check for a custom pageTitleSeparator, and perform stdWrap on it
+               if (isset($GLOBALS['TSFE']->config['config']['pageTitleSeparator']) && $GLOBALS['TSFE']->config['config']['pageTitleSeparator'] !== '') {
+                       $pageTitleSeparator = $GLOBALS['TSFE']->config['config']['pageTitleSeparator'];
+
+                       if (isset($GLOBALS['TSFE']->config['config']['pageTitleSeparator.']) && is_array($GLOBALS['TSFE']->config['config']['pageTitleSeparator.'])) {
+                               $pageTitleSeparator = $GLOBALS['TSFE']->cObj->stdWrap($pageTitleSeparator, $GLOBALS['TSFE']->config['config']['pageTitleSeparator.']);
+                       } else {
+                               $pageTitleSeparator .= ' ';
+                       }
+               }
+
                $titleTagContent = $GLOBALS['TSFE']->tmpl->printTitle(
-                       $GLOBALS['TSFE']->altPageTitle ? $GLOBALS['TSFE']->altPageTitle : $GLOBALS['TSFE']->page['title'],
+                       $GLOBALS['TSFE']->altPageTitle ?: $GLOBALS['TSFE']->page['title'],
                        $GLOBALS['TSFE']->config['config']['noPageTitle'],
-                       $GLOBALS['TSFE']->config['config']['pageTitleFirst']
+                       $GLOBALS['TSFE']->config['config']['pageTitleFirst'],
+                       $pageTitleSeparator
                );
                if ($GLOBALS['TSFE']->config['config']['titleTagFunction']) {
                        $titleTagContent = $GLOBALS['TSFE']->cObj->callUserFunction(