From c00ddcc58328e35ae675e1af5a8e1b5b1410da67 Mon Sep 17 00:00:00 2001 From: Benjamin Trenkle Date: Mon, 2 May 2022 09:57:31 +0200 Subject: [PATCH] [4.2] Fix wrong installation language select default value (#37252) * Fix language select on installation * Add method version * Updating Joomla Browser through composer dependencies (#129) * Revert API version --- composer.lock | 8 +- .../Form/Field/Installation/LanguageField.php | 96 +++++++++++++------ 2 files changed, 71 insertions(+), 33 deletions(-) diff --git a/composer.lock b/composer.lock index e332ab97c3847..71d70731a7558 100644 --- a/composer.lock +++ b/composer.lock @@ -7626,12 +7626,12 @@ "source": { "type": "git", "url": "https://github.com/joomla-projects/joomla-browser.git", - "reference": "3e7376f86ac634bd7674372b49394df104b852a2" + "reference": "a477f1054efc85096d72fa73501858c023bb8892" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/joomla-projects/joomla-browser/zipball/3e7376f86ac634bd7674372b49394df104b852a2", - "reference": "3e7376f86ac634bd7674372b49394df104b852a2", + "url": "https://api.github.com/repos/joomla-projects/joomla-browser/zipball/a477f1054efc85096d72fa73501858c023bb8892", + "reference": "a477f1054efc85096d72fa73501858c023bb8892", "shasum": "" }, "require": { @@ -7675,7 +7675,7 @@ "issues": "https://github.com/joomla-projects/joomla-browser/issues", "source": "https://github.com/joomla-projects/joomla-browser/tree/v4.0.0" }, - "time": "2022-04-15T21:05:43+00:00" + "time": "2022-04-14T11:45:55+00:00" }, { "name": "joomla/cms-coding-standards", diff --git a/installation/src/Form/Field/Installation/LanguageField.php b/installation/src/Form/Field/Installation/LanguageField.php index ac3b8d2c41a74..a1dcb6cf327cd 100644 --- a/installation/src/Form/Field/Installation/LanguageField.php +++ b/installation/src/Form/Field/Installation/LanguageField.php @@ -30,6 +30,26 @@ class LanguageField extends ListField */ protected $type = 'Language'; + /** + * Method to attach a Form object to the field. + * + * @param \SimpleXMLElement $element The SimpleXMLElement object representing the `` tag for the form field object. + * @param mixed $value The form field value to validate. + * @param string $group The field name group control value. This acts as as an array container for the field. + * For example if the field has name="foo" and the group value is set to "bar" then the + * full field name would end up being "bar[foo]". + * + * @return boolean True on success. + * + * @since __DEPLOY_VERSION__ + */ + public function setup(\SimpleXMLElement $element, $value, $group = null) + { + $value = $this->getNativeLanguage(); + + return parent::setup($element, $value, $group); + } + /** * Method to get the field options. * @@ -39,32 +59,7 @@ class LanguageField extends ListField */ protected function getOptions() { - $app = Factory::getApplication(); - - // Detect the native language. - $native = LanguageHelper::detectLanguage(); - - if (empty($native)) - { - $native = 'en-GB'; - } - - // Get a forced language if it exists. - $forced = $app->getLocalise(); - - if (!empty($forced['language'])) - { - $native = $forced['language']; - } - - // If a language is already set in the session, use this instead - $model = new SetupModel; - $options = $model->getOptions(); - - if (isset($options['language'])) - { - $native = $options['language']; - } + $native = $this->getNativeLanguage(); // Get the list of available languages. $options = LanguageHelper::createLanguageList($native); @@ -88,9 +83,6 @@ protected function getOptions() usort($options, array($this, '_sortLanguages')); } - // Set the default value from the native language. - $this->value = $native; - // Merge any additional options in the XML definition. $options = array_merge(parent::getOptions(), $options); @@ -111,4 +103,50 @@ protected function _sortLanguages($a, $b) { return strcmp($a['text'], $b['text']); } + + /** + * Determinate the native language to select + * + * @return string The native language to use + * + * @since __DEPLOY_VERSION__ + */ + protected function getNativeLanguage() + { + static $native; + + if (isset($native)) + { + return $native; + } + + $app = Factory::getApplication(); + + // Detect the native language. + $native = LanguageHelper::detectLanguage(); + + if (empty($native)) + { + $native = 'en-GB'; + } + + // Get a forced language if it exists. + $forced = $app->getLocalise(); + + if (!empty($forced['language'])) + { + $native = $forced['language']; + } + + // If a language is already set in the session, use this instead + $model = new SetupModel; + $options = $model->getOptions(); + + if (isset($options['language'])) + { + $native = $options['language']; + } + + return $native; + } }