You are here

public function ConfigTranslationFormBase::submitForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/config_translation/src/Form/ConfigTranslationFormBase.php \Drupal\config_translation\Form\ConfigTranslationFormBase::submitForm()
  2. 10 core/modules/config_translation/src/Form/ConfigTranslationFormBase.php \Drupal\config_translation\Form\ConfigTranslationFormBase::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 FormInterface::submitForm

2 calls to ConfigTranslationFormBase::submitForm()
ConfigTranslationAddForm::submitForm in core/modules/config_translation/src/Form/ConfigTranslationAddForm.php
Form submission handler.
ConfigTranslationEditForm::submitForm in core/modules/config_translation/src/Form/ConfigTranslationEditForm.php
Form submission handler.
2 methods override ConfigTranslationFormBase::submitForm()
ConfigTranslationAddForm::submitForm in core/modules/config_translation/src/Form/ConfigTranslationAddForm.php
Form submission handler.
ConfigTranslationEditForm::submitForm in core/modules/config_translation/src/Form/ConfigTranslationEditForm.php
Form submission handler.

File

core/modules/config_translation/src/Form/ConfigTranslationFormBase.php, line 197

Class

ConfigTranslationFormBase
Provides a base form for configuration translations.

Namespace

Drupal\config_translation\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $form_values = $form_state
    ->getValue([
    'translation',
    'config_names',
  ]);
  foreach ($form_values as $name => $value) {
    $schema = $this->typedConfigManager
      ->get($name);

    // Set configuration values based on form submission and source values.
    $base_config = $this
      ->configFactory()
      ->getEditable($name);
    $config_translation = $this->languageManager
      ->getLanguageConfigOverride($this->language
      ->getId(), $name);
    $element = $this
      ->createFormElement($schema);
    $element
      ->setConfig($base_config, $config_translation, $value);

    // If no overrides, delete language specific configuration file.
    $saved_config = $config_translation
      ->get();
    if (empty($saved_config)) {
      $config_translation
        ->delete();
    }
    else {
      $config_translation
        ->save();
    }
  }
  $form_state
    ->setRedirect($this->mapper
    ->getOverviewRoute(), $this->mapper
    ->getOverviewRouteParameters());
}