You are here

public function ConfigTranslationFormBase::submitForm in Drupal 10

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

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();
      $this
        ->messenger()
        ->addStatus($this
        ->t('@language translation was not added. To add a translation, you must modify the configuration.', [
        '@language' => $this->language
          ->getName(),
      ]));
    }
    else {
      $config_translation
        ->save();
      $this
        ->messenger()
        ->addStatus($this
        ->t('Successfully saved @language translation.', [
        '@language' => $this->language
          ->getName(),
      ]));
    }
  }
  $form_state
    ->setRedirect($this->mapper
    ->getOverviewRoute(), $this->mapper
    ->getOverviewRouteParameters());
}