[FEATURE] Make site title configurable per website language 01/62101/9
authorRichard Haeser <richard@maxserv.com>
Thu, 24 Oct 2019 14:54:40 +0000 (16:54 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Fri, 8 Nov 2019 05:14:27 +0000 (06:14 +0100)
The site title can now be configured with the site module instead of
using the sys_template record. If you don't need localized site titles
you can also set the title on a site base.

The site title in the sys_template record is deprecated now and will be
used as a fallback in v10.

Resolves: #85592
Releases: master
Change-Id: I1caea88ef9bb7c1a4550d68bff1ede91b6f5cb2a
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62101
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Kevin Appelt <kevin.appelt@icloud.com>
Tested-by: Chris Müller <typo3@krue.ml>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Kevin Appelt <kevin.appelt@icloud.com>
Reviewed-by: Chris Müller <typo3@krue.ml>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/backend/Configuration/SiteConfiguration/site.php
typo3/sysext/backend/Configuration/SiteConfiguration/site_language.php
typo3/sysext/backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf
typo3/sysext/backend/Resources/Private/Language/siteconfiguration_fieldinformation.xlf
typo3/sysext/core/Classes/Site/Entity/SiteLanguage.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-85592-DeprecatedSiteTitleConfiguration.rst [new file with mode: 0644]
typo3/sysext/core/Documentation/Changelog/master/Feature-85592-AddSiteTitleConfigurationToSitesModule.rst [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Site/Entity/SiteLanguageTest.php
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
typo3/sysext/frontend/Tests/Functional/Rendering/TitleTagRenderingTest.php

index 599fc6f..a26c91f 100644 (file)
@@ -53,6 +53,15 @@ return [
                 ],
             ],
         ],
+        'websiteTitle' => [
+            'label' => 'LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site.websiteTitle',
+            'description' => 'LLL:EXT:backend/Resources/Private/Language/siteconfiguration_fieldinformation.xlf:site.websiteTitle',
+            'config' => [
+                'type' => 'input',
+                'eval' => 'trim',
+                'default' => '',
+            ],
+        ],
         'languages' => [
             'label' => 'LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site.languages',
             'config' => [
@@ -107,7 +116,7 @@ return [
     ],
     'palettes' => [
         'default' => [
-            'showitem' => 'rootPageId, identifier'
+            'showitem' => 'rootPageId, identifier, --linebreak--, websiteTitle'
         ],
         'base' => [
             'showitem' => 'base, baseVariants'
index 0b1e48e..66e20e0 100644 (file)
@@ -53,6 +53,15 @@ return [
                 'placeholder' => '/',
             ],
         ],
+        'websiteTitle' => [
+            'label' => 'LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_language.websiteTitle',
+            'description' => 'LLL:EXT:backend/Resources/Private/Language/siteconfiguration_fieldinformation.xlf:site_language.websiteTitle',
+            'config' => [
+                'type' => 'input',
+                'eval' => 'trim',
+                'default' => '',
+            ],
+        ],
         'locale' => [
             'label' => 'LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_language.locale',
             'description' => 'LLL:EXT:backend/Resources/Private/Language/siteconfiguration_fieldinformation.xlf:site_language.locale',
@@ -445,7 +454,7 @@ return [
         ],
         'rendering-related' => [
             'label' => 'LLL:EXT:backend/Resources/Private/Language/locallang_siteconfiguration_tca.xlf:site_language.palette.frontend',
-            'showitem' => 'navigationTitle, hreflang, direction, --linebreak--, fallbackType, --linebreak--, fallbacks'
+            'showitem' => 'websiteTitle, --linebreak--, navigationTitle, hreflang, direction, --linebreak--, fallbackType, --linebreak--, fallbacks'
         ]
     ]
 ];
index b289c9c..ea59863 100644 (file)
@@ -15,6 +15,9 @@
                        <trans-unit id="site.base" resname="site.base">
                                <source>Entry Point</source>
                        </trans-unit>
+                       <trans-unit id="site.websiteTitle" resname="site.websiteTitle">
+                               <source>Website title</source>
+                       </trans-unit>
                        <trans-unit id="site.baseVariants" resname="site.baseVariants">
                                <source>Variants for the Entry Point</source>
                        </trans-unit>
@@ -55,6 +58,9 @@
                        <trans-unit id="site_language.title" resname="site_language.title">
                                <source>Title</source>
                        </trans-unit>
+                       <trans-unit id="site_language.websiteTitle" resname="site_language.websiteTitle">
+                               <source>Website title</source>
+                       </trans-unit>
                        <trans-unit id="site_language.navigationTitle" resname="site_language.navigationTitle">
                                <source>Navigation Title</source>
                        </trans-unit>
index 4a45d4d..5162a23 100644 (file)
@@ -13,6 +13,9 @@
                                <source>Main URL to call the frontend in default language. Can be https://www.example.com/ or just /, if it is just a / you cannot rely on TYPO3 creating
                                        full URLs</source>
                        </trans-unit>
+                       <trans-unit id="site.websiteTitle" resname="site.websiteTitle">
+                               <source>The title of the website is used for the title tag in the frontend</source>
+                       </trans-unit>
                        <trans-unit id="site.baseVariants" resname="site.baseVariants">
                                <source>This allows you to specify variants of the site's base. Can be used, for example, if you have a different domain for your staging environment.</source>
                        </trans-unit>
@@ -28,6 +31,9 @@
                        <trans-unit id="site_language.hreflang" resname="site_language.hreflang">
                                <source>Used within for "lang" and "hreflang" attributes</source>
                        </trans-unit>
+                       <trans-unit id="site_language.websiteTitle" resname="site_language.websiteTitle">
+                               <source>With this language based Website title, you can override the Website title for this language</source>
+                       </trans-unit>
                        <trans-unit id="site_language.navigationTitle" resname="site_language.navigationTitle">
                                <source>Used within language-related menus</source>
                        </trans-unit>
index 0064027..c9aaf64 100644 (file)
@@ -57,6 +57,12 @@ class SiteLanguage
     protected $navigationTitle = '';
 
     /**
+     * Localized title of the site to be used in title tag.
+     * @var string
+     */
+    protected $websiteTitle = '';
+
+    /**
      * The flag key (like "gb" or "fr") used to be used in TYPO3's Backend.
      * @var string
      */
@@ -133,6 +139,9 @@ class SiteLanguage
         if (!empty($configuration['navigationTitle'])) {
             $this->navigationTitle = $configuration['navigationTitle'];
         }
+        if (!empty($configuration['websiteTitle'])) {
+            $this->websiteTitle = $configuration['websiteTitle'];
+        }
         if (!empty($configuration['flag'])) {
             $this->flagIdentifier = $configuration['flag'];
         }
@@ -184,6 +193,7 @@ class SiteLanguage
             'locale' => $this->getLocale(),
             'base' => (string)$this->getBase(),
             'title' => $this->getTitle(),
+            'websiteTitle' => $this->getWebsiteTitle(),
             'navigationTitle' => $this->getNavigationTitle(),
             'twoLetterIsoCode' => $this->getTwoLetterIsoCode(),
             'hreflang' => $this->getHreflang(),
@@ -239,6 +249,14 @@ class SiteLanguage
     /**
      * @return string
      */
+    public function getWebsiteTitle(): string
+    {
+        return $this->websiteTitle;
+    }
+
+    /**
+     * @return string
+     */
     public function getFlagIdentifier(): string
     {
         return $this->flagIdentifier;
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85592-DeprecatedSiteTitleConfiguration.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85592-DeprecatedSiteTitleConfiguration.rst
new file mode 100644 (file)
index 0000000..8646e09
--- /dev/null
@@ -0,0 +1,34 @@
+.. include:: ../../Includes.txt
+
+=========================================================
+Deprecation: #85592 - Deprecated site title configuration
+=========================================================
+
+See :issue:`85592`
+
+Description
+===========
+
+Defining the site title in the sys_template record (`sys_template.sitetitle` field) has been deprecated and should not be
+used any longer. This field (database and TCA) will be removed in v11.
+
+
+Impact
+======
+
+The field will be removed in version 11. In version 10 the site title in the sys_template will be used as a
+fallback when no Site title is set in the site configuration.
+
+
+Affected Installations
+======================
+
+Instances defining the site title in the sys_template record.
+
+
+Migration
+=========
+
+Copy the site title to the new available field in the site module language configuration.
+
+.. index:: Frontend, NotScanned
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-85592-AddSiteTitleConfigurationToSitesModule.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-85592-AddSiteTitleConfigurationToSitesModule.rst
new file mode 100644 (file)
index 0000000..1db862c
--- /dev/null
@@ -0,0 +1,27 @@
+.. include:: ../../Includes.txt
+
+==============================================================
+Feature: #85592 - Add site title configuration to sites module
+==============================================================
+
+See :issue:`85592`
+
+Description
+===========
+
+The site title can now be configured within the sites module instead of using the field in the system template record.
+This allows now a different site title per language.
+
+This site title will be used for the page title as well as for future schema.org integrations.
+
+
+Impact
+======
+
+The new way allows now to have a different site title per language.
+
+The old way using the system template record has been deprecated and will be removed in TYPO3 v11. When you have set
+the site title in your site configuration, it will take precedence over your TypoScript setting. Overriding your
+site title with a TypoScript extension template is not possible anymore when using the site configuration.
+
+.. index:: Backend, Frontend
index c466d63..84721da 100644 (file)
@@ -91,6 +91,7 @@ class SiteLanguageTest extends UnitTestCase
             'locale' => 'de',
             'base' => '/',
             'title' => 'Default',
+            'websiteTitle' => '',
             'twoLetterIsoCode' => 'en',
             'hreflang' => 'en-US',
             'direction' => '',
index 66ed2fb..c108542 100644 (file)
@@ -2883,21 +2883,44 @@ class TypoScriptFrontendController implements LoggerAwareInterface
      */
     protected function printTitle(string $pageTitle, bool $noTitle = false, bool $showTitleFirst = false, string $pageTitleSeparator = ''): string
     {
-        $siteTitle = trim($this->tmpl->setup['sitetitle'] ?? '');
+        $websiteTitle = $this->getWebsiteTitle();
         $pageTitle = $noTitle ? '' : $pageTitle;
         if ($showTitleFirst) {
-            $temp = $siteTitle;
-            $siteTitle = $pageTitle;
+            $temp = $websiteTitle;
+            $websiteTitle = $pageTitle;
             $pageTitle = $temp;
         }
         // only show a separator if there are both site title and page title
-        if ($pageTitle === '' || $siteTitle === '') {
+        if ($pageTitle === '' || $websiteTitle === '') {
             $pageTitleSeparator = '';
         } elseif (empty($pageTitleSeparator)) {
             // use the default separator if non given
             $pageTitleSeparator = ': ';
         }
-        return $siteTitle . $pageTitleSeparator . $pageTitle;
+        return $websiteTitle . $pageTitleSeparator . $pageTitle;
+    }
+
+    /**
+     * @return string
+     */
+    protected function getWebsiteTitle(): string
+    {
+        if ($this->language instanceof SiteLanguage
+            && trim($this->language->getWebsiteTitle()) !== ''
+        ) {
+            return trim($this->language->getWebsiteTitle());
+        }
+        if ($this->site instanceof SiteInterface
+            && trim($this->site->getConfiguration()['websiteTitle']) !== ''
+        ) {
+            return trim($this->site->getConfiguration()['websiteTitle']);
+        }
+        if (!empty($this->tmpl->setup['sitetitle'])) {
+            // @deprecated since TYPO3 v10.2 and will be removed in TYPO3 v11.0
+            return trim($this->tmpl->setup['sitetitle']);
+        }
+
+        return '';
     }
 
     /**
index 988f7e5..75ba2d3 100644 (file)
@@ -67,6 +67,7 @@ class TitleTagRenderingTest extends FunctionalTestCase
         $configuration = [
             'rootPageId' => $pageId,
             'base' => '/',
+            'websiteTitle' => '',
             'languages' => [
                 [
                     'title' => 'English',
@@ -76,6 +77,7 @@ class TitleTagRenderingTest extends FunctionalTestCase
                     'typo3Language' => 'default',
                     'locale' => 'en_US.UTF-8',
                     'iso-639-1' => 'en',
+                    'websiteTitle' => '',
                     'navigationTitle' => '',
                     'hreflang' => '',
                     'direction' => '',