Skip to content

Commit

Permalink
[BUGFIX] Allow setting of default language (#15)
Browse files Browse the repository at this point in the history
* [BUGFIX] Allow setting of default language

Releases: master, 10, 9

* [BUGFIX] Improve wording in manual

Co-authored-by: Andreas Fernandez <andreas.fernandez@typo3.com>
  • Loading branch information
NeoBlack and andreaskienast committed Aug 6, 2020
1 parent fb1b095 commit 6e526ba
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Classes/Hooks/PageRendererPreProcess.php
Expand Up @@ -38,7 +38,7 @@ public function addLibrary(): void
if (!$this->isValidId($config)) {
throw new \InvalidArgumentException('Usercentrics ID not configured, please set plugin.tx_usercentrics.settingsId in your TypoScript configuration', 1583774571);
}
$this->addUsercentricsScript($config['settingsId']);
$this->addUsercentricsScript($config);
$this->addConfiguredJsFiles($config['jsFiles.'] ?? []);
$this->addConfiguredInlineJavaScript($config['jsInline.'] ?? []);
}
Expand Down Expand Up @@ -75,11 +75,12 @@ protected function addConfiguredJsFiles(array $jsFiles): void
}
}

protected function addUsercentricsScript(string $settingsId): void
protected function addUsercentricsScript(array $config): void
{
$this->assetCollector->addJavaScript('usercentrics', 'https://app.usercentrics.eu/latest/main.js', [
'type' => 'application/javascript',
'id' => $settingsId
'id' => $config['settingsId'],
'language' => $config['language'],
]);
}

Expand Down
2 changes: 2 additions & 0 deletions Configuration/TypoScript/Static/constants.typoscript
Expand Up @@ -4,5 +4,7 @@ plugin {
tx_usercentrics {
# cat=usercentrics; type=string; label=Usercentrics ID
settingsId =
# cat=usercentrics; type=string; label=language iso code
language = en
}
}
1 change: 1 addition & 0 deletions Configuration/TypoScript/Static/setup.typoscript
@@ -1,4 +1,5 @@
plugin.tx_usercentrics {
id = {$plugin.tx_usercentrics.settingsId}
language = {$plugin.tx_usercentrics.language}
}

13 changes: 13 additions & 0 deletions Documentation/Configuration/Index.rst
Expand Up @@ -32,3 +32,16 @@ In TypoScript, set the constant as follows:
plugin.tx_usercentrics.settingsId = XXXXXXXX
Configure The Usercentrics Default language
===========================================

The extension ships a TypoScript constant that allows to set the default language to be used.
The language must be enabled in the Usercentrics account settings and provided as ISO 639-1 code.

In TypoScript, set the constant as follows:

.. code-block:: typoscript
plugin.tx_usercentrics.language = en
8 changes: 8 additions & 0 deletions Tests/Unit/PageRendererPreProcessTest.php
Expand Up @@ -63,6 +63,7 @@ public function addLibraryAddsMainUsercentricsScript(): void
'plugin.' => [
'tx_usercentrics.' => [
'settingsId' => 'myUsercentricsId',
'language' => 'en',
],
],
];
Expand All @@ -73,6 +74,7 @@ public function addLibraryAddsMainUsercentricsScript(): void
$this->assetCollector->addJavaScript('usercentrics', 'https://app.usercentrics.eu/latest/main.js', [
'type' => 'application/javascript',
'id' => 'myUsercentricsId',
'language' => 'en',
])->shouldHaveBeenCalled();
}

Expand All @@ -85,6 +87,7 @@ public function addLibraryThrowsExceptionIfNoIdentifierGivenForFile(): void
'plugin.' => [
'tx_usercentrics.' => [
'settingsId' => 'myUsercentricsId',
'language' => 'en',
'jsFiles.' => [
'10.' => [
'file' => 'EXT:site/Resources/Public/JavaScript/test.js',
Expand All @@ -109,6 +112,7 @@ public function addLibraryThrowsExceptionIfNoFileGiven(): void
'plugin.' => [
'tx_usercentrics.' => [
'settingsId' => 'myUsercentricsId',
'language' => 'en',
'jsFiles.' => [
'10.' => [
],
Expand All @@ -134,6 +138,7 @@ public function addLibraryAddsConfiguredFileWithAttributes(): void
'plugin.' => [
'tx_usercentrics.' => [
'settingsId' => 'myUsercentricsId',
'language' => 'en',
'jsFiles.' => [
'10.' => [
'file' => $file,
Expand Down Expand Up @@ -169,6 +174,7 @@ public function addLibraryAddsConfiguredFileWithAttributesAndOptions(): void
'plugin.' => [
'tx_usercentrics.' => [
'settingsId' => 'myUsercentricsId',
'language' => 'en',
'jsFiles.' => [
'10.' => [
'file' => $file,
Expand Down Expand Up @@ -208,6 +214,7 @@ public function addLibraryThrowsExceptionIfNoIdentifierGivenForInlineJs(): void
'plugin.' => [
'tx_usercentrics.' => [
'settingsId' => 'myUsercentricsId',
'language' => 'en',
'jsInline.' => [
'10.' => [
'value' => 'alert(123);',
Expand All @@ -234,6 +241,7 @@ public function addLibraryAddsInlineJsWithAttributesAndOptions(): void
'plugin.' => [
'tx_usercentrics.' => [
'settingsId' => 'myUsercentricsId',
'language' => 'en',
'jsInline.' => [
'10.' => [
'value' => $value,
Expand Down

0 comments on commit 6e526ba

Please sign in to comment.