Skip to content

Commit

Permalink
[FEATURE] Make SiteLanguage available in TypoScript
Browse files Browse the repository at this point in the history
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/59302
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: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
  • Loading branch information
georgringer authored and janhelke committed Dec 28, 2018
1 parent 30cf5b6 commit 7e8931a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
@@ -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
Expand Up @@ -48,6 +48,7 @@
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;
Expand Down Expand Up @@ -5105,6 +5106,16 @@ public function getData($string, $fieldArray = null)
}
}
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;
}
}

Expand Down
Expand Up @@ -25,6 +25,7 @@
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;
Expand All @@ -33,6 +34,7 @@
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;
Expand Down Expand Up @@ -1692,7 +1694,7 @@ public function getDataWithTypeContext(): void
}

/**
* Checks if getData() works with type "context"
* Checks if getData() works with type "site"
*
* @test
*/
Expand All @@ -1713,6 +1715,23 @@ public function getDataWithTypeSite(): void
$this->assertEquals('yeah', $this->subject->getData('site:custom.config.nested'));
}

/**
* 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"
*
Expand Down

0 comments on commit 7e8931a

Please sign in to comment.