/**
  * {@inheritdoc}
  */
 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.'));
 }