You are here

protected function LingotekSettingsTabPreferencesForm::saveLanguageSwitcherSettings in Lingotek Translation 3.2.x

Same name and namespace in other branches
  1. 8 src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm::saveLanguageSwitcherSettings()
  2. 8.2 src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm::saveLanguageSwitcherSettings()
  3. 4.0.x src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm::saveLanguageSwitcherSettings()
  4. 3.0.x src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm::saveLanguageSwitcherSettings()
  5. 3.1.x src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm::saveLanguageSwitcherSettings()
  6. 3.3.x src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm::saveLanguageSwitcherSettings()
  7. 3.4.x src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm::saveLanguageSwitcherSettings()
  8. 3.5.x src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm::saveLanguageSwitcherSettings()
  9. 3.6.x src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm::saveLanguageSwitcherSettings()
  10. 3.7.x src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm::saveLanguageSwitcherSettings()
  11. 3.8.x src/Form/LingotekSettingsTabPreferencesForm.php \Drupal\lingotek\Form\LingotekSettingsTabPreferencesForm::saveLanguageSwitcherSettings()
1 call to LingotekSettingsTabPreferencesForm::saveLanguageSwitcherSettings()
LingotekSettingsTabPreferencesForm::submitForm in src/Form/LingotekSettingsTabPreferencesForm.php
Form submission handler.

File

src/Form/LingotekSettingsTabPreferencesForm.php, line 224

Class

LingotekSettingsTabPreferencesForm
Configure Lingotek

Namespace

Drupal\lingotek\Form

Code

protected function saveLanguageSwitcherSettings($form_values) {

  // If the website doesn't have a language switcher yet, don't act on it.
  if ($this->lang_switcher) {
    $this->lang_switcher
      ->setRegion($form_values['lang_switcher_select']);
    if ($form_values['lang_switcher']) {
      $this->lang_switcher
        ->enable();
    }
    else {
      $this->lang_switcher
        ->disable();
    }
    $this->lang_switcher
      ->save();
  }
  else {

    // If the user selects the checkbox, and no language switcher exists yet, create one.
    if ($form_values['lang_switcher']) {
      $config = $this
        ->config('system.theme');
      $theme_default = $config
        ->get('default');
      $this->lang_switcher = \Drupal::entityTypeManager()
        ->getStorage('block')
        ->create([
        'plugin' => 'language_block:language_interface',
        'theme' => $theme_default,
      ]);
      $this->lang_switcher
        ->setRegion($form_values['lang_switcher_select']);
      $this->lang_switcher
        ->enable();
      $this->lang_switcher
        ->set('id', 'languageswitcher');
      $this->lang_switcher
        ->save();
    }
  }
}