You are here

public function NegotiationConfigureForm::submitForm in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/language/src/Form/NegotiationConfigureForm.php \Drupal\language\Form\NegotiationConfigureForm::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides ConfigFormBase::submitForm

File

core/modules/language/src/Form/NegotiationConfigureForm.php, line 163
Contains \Drupal\language\Form\NegotiationConfigureForm.

Class

NegotiationConfigureForm
Configure the selected language negotiation method for this site.

Namespace

Drupal\language\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $configurable_types = $form['#language_types'];
  $stored_values = $this->languageTypes
    ->get('configurable');
  $customized = array();
  $method_weights_type = array();
  foreach ($configurable_types as $type) {
    $customized[$type] = in_array($type, $stored_values);
    $method_weights = array();
    $enabled_methods = $form_state
      ->getValue(array(
      $type,
      'enabled',
    ));
    $enabled_methods[LanguageNegotiationSelected::METHOD_ID] = TRUE;
    $method_weights_input = $form_state
      ->getValue(array(
      $type,
      'weight',
    ));
    if ($form_state
      ->hasValue(array(
      $type,
      'configurable',
    ))) {
      $customized[$type] = !$form_state
        ->isValueEmpty(array(
        $type,
        'configurable',
      ));
    }
    foreach ($method_weights_input as $method_id => $weight) {
      if ($enabled_methods[$method_id]) {
        $method_weights[$method_id] = $weight;
      }
    }
    $method_weights_type[$type] = $method_weights;
    $this->languageTypes
      ->set('negotiation.' . $type . '.method_weights', $method_weights_input)
      ->save();
  }

  // Update non-configurable language types and the related language
  // negotiation configuration.
  $this->negotiator
    ->updateConfiguration(array_keys(array_filter($customized)));

  // Update the language negotiations after setting the configurability.
  foreach ($method_weights_type as $type => $method_weights) {
    $this->negotiator
      ->saveConfiguration($type, $method_weights);
  }

  // Clear block definitions cache since the available blocks and their names
  // may have been changed based on the configurable types.
  if ($this->blockStorage) {

    // If there is an active language switcher for a language type that has
    // been made not configurable, deactivate it first.
    $non_configurable = array_keys(array_diff($customized, array_filter($customized)));
    $this
      ->disableLanguageSwitcher($non_configurable);
  }
  $this->blockManager
    ->clearCachedDefinitions();
  $form_state
    ->setRedirect('language.negotiation');
  drupal_set_message($this
    ->t('Language detection configuration saved.'));
}