[TASK] Add full configuration to SiteLanguage::toArray
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Site / Entity / SiteLanguage.php
index 2ad4b89..d20ea92 100644 (file)
@@ -16,6 +16,8 @@ namespace TYPO3\CMS\Core\Site\Entity;
  * The TYPO3 project - inspiring people to share!
  */
 
+use Psr\Http\Message\UriInterface;
+
 /**
  * Entity representing a site_language configuration of a site object.
  */
@@ -38,7 +40,7 @@ class SiteLanguage
     /**
      * The Base URL for this language
      *
-     * @var string
+     * @var UriInterface
      */
     protected $base;
 
@@ -58,7 +60,7 @@ class SiteLanguage
      * The flag key (like "gb" or "fr") used to be used in TYPO3's Backend.
      * @var string
      */
-    protected $flagIdentifier = 'us';
+    protected $flagIdentifier = '';
 
     /**
      * The iso code for this language (two letter) ISO-639-1
@@ -108,51 +110,52 @@ class SiteLanguage
      * Additional parameters configured for this site language
      * @var array
      */
-    protected $attributes = [];
+    protected $configuration = [];
 
     /**
      * SiteLanguage constructor.
      *
      * @param int $languageId
      * @param string $locale
-     * @param string $base
-     * @param array $attributes
+     * @param UriInterface $base
+     * @param array $configuration
      */
-    public function __construct(int $languageId, string $locale, string $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 (!empty($attributes['fallbacks'])) {
-            $this->fallbackLanguageIds = $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'];
         }
     }
 
@@ -164,10 +167,10 @@ class SiteLanguage
      */
     public function toArray(): array
     {
-        return [
+        return array_merge($this->configuration, [
             'languageId' => $this->getLanguageId(),
             'locale' => $this->getLocale(),
-            'base' => $this->getBase(),
+            'base' => (string)$this->getBase(),
             'title' => $this->getTitle(),
             'navigationTitle' => $this->getNavigationTitle(),
             'twoLetterIsoCode' => $this->getTwoLetterIsoCode(),
@@ -178,7 +181,7 @@ class SiteLanguage
             'fallbackType' => $this->getFallbackType(),
             'enabled' => $this->enabled(),
             'fallbackLanguageIds' => $this->getFallbackLanguageIds(),
-        ];
+        ]);
     }
 
     /**
@@ -198,9 +201,9 @@ class SiteLanguage
     }
 
     /**
-     * @return string
+     * @return UriInterface
      */
-    public function getBase(): string
+    public function getBase(): UriInterface
     {
         return $this->base;
     }
@@ -218,7 +221,7 @@ class SiteLanguage
      */
     public function getNavigationTitle(): string
     {
-        return $this->navigationTitle ?: $this->getTitle();
+        return $this->navigationTitle ?: $this->title;
     }
 
     /**
@@ -278,6 +281,16 @@ class SiteLanguage
     }
 
     /**
+     * Helper so fluid can work with this as well.
+     *
+     * @return bool
+     */
+    public function isEnabled(): bool
+    {
+        return $this->enabled;
+    }
+
+    /**
      * @return string
      */
     public function getFallbackType(): string