[TASK] Add full configuration to SiteLanguage::toArray 25/59025/4
authorGeorg Ringer <georg.ringer@gmail.com>
Tue, 4 Dec 2018 12:28:19 +0000 (13:28 +0100)
committerMarkus Klein <markus.klein@typo3.org>
Fri, 7 Dec 2018 20:51:32 +0000 (21:51 +0100)
Make the full configuration of a SiteLanguage available. This is required
to get access to an extended site language configuration.

To be in sync to the Site object, the property attributes is renamed to
configuration.

Resolves: #87027
Releases: master
Change-Id: I8962c5f7cafb38398bf9ded77058af38828e7182
Reviewed-on: https://review.typo3.org/59025
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Josef Glatz <josef.glatz@typo3.org>
Tested-by: Josef Glatz <josef.glatz@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/core/Classes/Site/Entity/SiteLanguage.php
typo3/sysext/core/Tests/Unit/Site/Entity/SiteLanguageTest.php [new file with mode: 0644]

index fc4917e..d20ea92 100644 (file)
@@ -110,7 +110,7 @@ class SiteLanguage
      * Additional parameters configured for this site language
      * @var array
      */
-    protected $attributes = [];
+    protected $configuration = [];
 
     /**
      * SiteLanguage constructor.
@@ -118,43 +118,44 @@ class SiteLanguage
      * @param int $languageId
      * @param string $locale
      * @param UriInterface $base
-     * @param array $attributes
+     * @param array $configuration
      */
-    public function __construct(int $languageId, string $locale, UriInterface $base, array $attributes)
+    public function __construct(int $languageId, string $locale, UriInterface $base, array $configuration)
     {
         $this->languageId = $languageId;
         $this->locale = $locale;
         $this->base = $base;
-        $this->attributes = $attributes;
-        if (!empty($attributes['title'])) {
-            $this->title = $attributes['title'];
+        $this->configuration = $configuration;
+
+        if (!empty($configuration['title'])) {
+            $this->title = $configuration['title'];
         }
-        if (!empty($attributes['navigationTitle'])) {
-            $this->navigationTitle = $attributes['navigationTitle'];
+        if (!empty($configuration['navigationTitle'])) {
+            $this->navigationTitle = $configuration['navigationTitle'];
         }
-        if (!empty($attributes['flag'])) {
-            $this->flagIdentifier = $attributes['flag'];
+        if (!empty($configuration['flag'])) {
+            $this->flagIdentifier = $configuration['flag'];
         }
-        if (!empty($attributes['typo3Language'])) {
-            $this->typo3Language = $attributes['typo3Language'];
+        if (!empty($configuration['typo3Language'])) {
+            $this->typo3Language = $configuration['typo3Language'];
         }
-        if (!empty($attributes['iso-639-1'])) {
-            $this->twoLetterIsoCode = $attributes['iso-639-1'];
+        if (!empty($configuration['iso-639-1'])) {
+            $this->twoLetterIsoCode = $configuration['iso-639-1'];
         }
-        if (!empty($attributes['hreflang'])) {
-            $this->hreflang = $attributes['hreflang'];
+        if (!empty($configuration['hreflang'])) {
+            $this->hreflang = $configuration['hreflang'];
         }
-        if (!empty($attributes['direction'])) {
-            $this->direction = $attributes['direction'];
+        if (!empty($configuration['direction'])) {
+            $this->direction = $configuration['direction'];
         }
-        if (!empty($attributes['fallbackType'])) {
-            $this->fallbackType = $attributes['fallbackType'];
+        if (!empty($configuration['fallbackType'])) {
+            $this->fallbackType = $configuration['fallbackType'];
         }
-        if (isset($attributes['fallbacks'])) {
-            $this->fallbackLanguageIds = is_array($attributes['fallbacks']) ? $attributes['fallbacks'] : explode(',', $attributes['fallbacks']);
+        if (isset($configuration['fallbacks'])) {
+            $this->fallbackLanguageIds = is_array($configuration['fallbacks']) ? $configuration['fallbacks'] : explode(',', $configuration['fallbacks']);
         }
-        if (isset($attributes['enabled'])) {
-            $this->enabled = (bool)$attributes['enabled'];
+        if (isset($configuration['enabled'])) {
+            $this->enabled = (bool)$configuration['enabled'];
         }
     }
 
@@ -166,7 +167,7 @@ class SiteLanguage
      */
     public function toArray(): array
     {
-        return [
+        return array_merge($this->configuration, [
             'languageId' => $this->getLanguageId(),
             'locale' => $this->getLocale(),
             'base' => (string)$this->getBase(),
@@ -180,7 +181,7 @@ class SiteLanguage
             'fallbackType' => $this->getFallbackType(),
             'enabled' => $this->enabled(),
             'fallbackLanguageIds' => $this->getFallbackLanguageIds(),
-        ];
+        ]);
     }
 
     /**
@@ -220,7 +221,7 @@ class SiteLanguage
      */
     public function getNavigationTitle(): string
     {
-        return $this->navigationTitle ?: $this->getTitle();
+        return $this->navigationTitle ?: $this->title;
     }
 
     /**
diff --git a/typo3/sysext/core/Tests/Unit/Site/Entity/SiteLanguageTest.php b/typo3/sysext/core/Tests/Unit/Site/Entity/SiteLanguageTest.php
new file mode 100644 (file)
index 0000000..2008f7a
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+declare(strict_types = 1);
+
+namespace TYPO3\CMS\Core\Tests\Unit\Site\Entity;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Http\Uri;
+use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+
+class SiteLanguageTest extends UnitTestCase
+{
+    /**
+     * @test
+     */
+    public function toArrayReturnsProperOverlaidData()
+    {
+        $configuration = [
+            'navigationTitle' => 'NavTitle',
+            'customValue' => 'a custom value'
+        ];
+        $subject = new SiteLanguage(1, 'de', new Uri('/'), $configuration);
+        $expected = [
+            'languageId' => 1,
+            'locale' => 'de',
+            'base' => '/',
+            'title' => 'Default',
+            'navigationTitle' => 'NavTitle',
+            'twoLetterIsoCode' => 'en',
+            'hreflang' => 'en-US',
+            'direction' => '',
+            'typo3Language' => 'default',
+            'flagIdentifier' => '',
+            'fallbackType' => 'strict',
+            'enabled' => true,
+            'fallbackLanguageIds' => [],
+            'customValue' => 'a custom value'
+        ];
+        $this->assertEquals($expected, $subject->toArray());
+    }
+}