[FEATURE] Make SiteLanguage available in TypoScript 30/58930/11
authorGeorg Ringer <georg.ringer@gmail.com>
Thu, 22 Nov 2018 07:46:21 +0000 (08:46 +0100)
committerJan Helke <typo3@helke.de>
Fri, 28 Dec 2018 10:50:47 +0000 (11:50 +0100)
The current language configuration should be available in TS as well.

Resolves: #86973
Releases: master, 9.5
Change-Id: Iae71b550b3d000b12b4e127fee751740c3a36bf7
Reviewed-on: https://review.typo3.org/58930
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Josef Glatz <josef.glatz@typo3.org>
Tested-by: Josef Glatz <josef.glatz@typo3.org>
Reviewed-by: Jörg Bösche <typo3@joergboesche.de>
Tested-by: Jörg Bösche <typo3@joergboesche.de>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
typo3/sysext/core/Documentation/Changelog/9.5.x/Feature-86973-TypoScriptGetTextPropertySiteLanguage.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php

diff --git a/typo3/sysext/core/Documentation/Changelog/9.5.x/Feature-86973-TypoScriptGetTextPropertySiteLanguage.rst b/typo3/sysext/core/Documentation/Changelog/9.5.x/Feature-86973-TypoScriptGetTextPropertySiteLanguage.rst
new file mode 100644 (file)
index 0000000..6366893
--- /dev/null
@@ -0,0 +1,33 @@
+.. include:: ../../Includes.txt
+
+==========================================================
+Feature: #86973 - TypoScript getText property siteLanguage
+==========================================================
+
+See :issue:`86973`
+
+Description
+===========
+
+Site language configuration can now be accessed via the :typoscript:`getText` property `siteLanguage`
+in TypoScript.
+
+Examples:
+
+.. code-block:: typoscript
+
+       page.10 = TEXT
+       page.10.data = siteLanguage:navigationTitle
+       page.10.wrap = This is the title of the current site language: |
+
+.. code-block:: typoscript
+
+       page.10 = TEXT
+       page.10.dataWrap = The current site language direction is {siteLanguage:direction}
+
+Impact
+======
+
+Accessing the current site language configuration is now possible in TypoScript.
+
+.. index:: PHP-API, ext:frontend, NotScanned
index 987f434..52004fd 100644 (file)
@@ -47,6 +47,7 @@ use TYPO3\CMS\Core\Service\DependencyOrderingService;
 use TYPO3\CMS\Core\Service\FlexFormService;
 use TYPO3\CMS\Core\Service\MarkerBasedTemplateService;
 use TYPO3\CMS\Core\Site\Entity\Site;
+use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
 use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
 use TYPO3\CMS\Core\TypoScript\TypoScriptService;
@@ -4703,6 +4704,16 @@ class ContentObjectRenderer implements LoggerAwareInterface
                             }
                         }
                         break;
+                    case 'sitelanguage':
+                        $request = $GLOBALS['TYPO3_REQUEST'] ?? null;
+                        $siteLanguage = $request ? $request->getAttribute('language') : null;
+                        if ($siteLanguage instanceof SiteLanguage) {
+                            $config = $siteLanguage->toArray();
+                            if (isset($config[$key])) {
+                                $retVal = $config[$key];
+                            }
+                        }
+                        break;
                 }
             }
 
index b3925a5..0f659f5 100644 (file)
@@ -25,6 +25,7 @@ use TYPO3\CMS\Core\Context\Context;
 use TYPO3\CMS\Core\Context\UserAspect;
 use TYPO3\CMS\Core\Context\WorkspaceAspect;
 use TYPO3\CMS\Core\Core\ApplicationContext;
+use TYPO3\CMS\Core\Http\Uri;
 use TYPO3\CMS\Core\LinkHandling\LinkService;
 use TYPO3\CMS\Core\Log\Logger;
 use TYPO3\CMS\Core\Package\PackageManager;
@@ -33,6 +34,7 @@ use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Resource\ResourceStorage;
 use TYPO3\CMS\Core\Site\Entity\Site;
+use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
 use TYPO3\CMS\Core\TypoScript\TemplateService;
 use TYPO3\CMS\Core\Utility\DebugUtility;
@@ -1692,7 +1694,7 @@ class ContentObjectRendererTest extends UnitTestCase
     }
 
     /**
-     * Checks if getData() works with type "context"
+     * Checks if getData() works with type "site"
      *
      * @test
      */
@@ -1714,6 +1716,23 @@ class ContentObjectRendererTest extends UnitTestCase
     }
 
     /**
+     * Checks if getData() works with type "siteLanguage"
+     *
+     * @test
+     */
+    public function getDataWithTypeSiteLanguage(): void
+    {
+        $site = new SiteLanguage(1, 'de-de', new Uri('/'), [
+            'title' => 'languageTitle',
+            'navigationTitle' => 'German'
+        ]);
+        $serverRequest = $this->prophesize(ServerRequestInterface::class);
+        $serverRequest->getAttribute('language')->willReturn($site);
+        $GLOBALS['TYPO3_REQUEST'] = $serverRequest->reveal();
+        $this->assertEquals('German', $this->subject->getData('siteLanguage:navigationTitle'));
+    }
+
+    /**
      * Checks if getData() works with type "parentRecordNumber"
      *
      * @test