Skip to content

Commit

Permalink
Avoid empty language setting, refs #13465
Browse files Browse the repository at this point in the history
Make `languageCode` required but keep the allow empty option for
display. Restructure validation to show the enabled languages on error.
  • Loading branch information
jraddaoui authored and sbreker committed Mar 18, 2021
1 parent 136f816 commit f3a79ae
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions apps/qubit/modules/settings/actions/languageAction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,38 @@ class SettingsLanguageAction extends sfAction
{
public function execute($request)
{
$this->form = new sfForm;
$this->form->setValidator('languageCode', new sfValidatorI18nChoiceLanguage(array('required' => true)));
$this->form->setWidget('languageCode', new sfWidgetFormI18nChoiceLanguage(array('add_empty' => true, 'culture' => $this->context->user->getCulture())));

// Handle POST data (form submit)
if ($request->isMethod('post'))
{
QubitCache::getInstance()->removePattern('settings:i18n:*');
$this->form->bind($request->getPostParameters());

if (null !== $languageCode = $request->languageCode)
if ($this->form->isValid())
{
try
{
ProjectConfiguration::getActive()->loadHelpers('I18N');

format_language($languageCode, $languageCode);
format_language($request->languageCode, $request->languageCode);
}
catch (Exception $e)
{
$this->redirect(array('module' => 'settings', 'action' => 'language'));
}

QubitCache::getInstance()->removePattern('settings:i18n:*');

$setting = new QubitSetting;
$setting->name = $languageCode;
$setting->name = $request->languageCode;
$setting->scope = 'i18n_languages';
$setting->value = $languageCode;
$setting->value = $request->languageCode;
$setting->deleteable = true;
$setting->editable = true;
$setting->getCurrentSettingI18n()->setCulture('en');
$setting->sourceCulture = 'en';

$setting->save();

$notice = sfContext::getInstance()->i18n->__('Language saved.');
Expand Down

0 comments on commit f3a79ae

Please sign in to comment.