function ThemeSettingsForm::submitForm

Same name and namespace in other branches
  1. 9 core/modules/system/src/Form/ThemeSettingsForm.php \Drupal\system\Form\ThemeSettingsForm::submitForm()
  2. 8.9.x core/modules/system/src/Form/ThemeSettingsForm.php \Drupal\system\Form\ThemeSettingsForm::submitForm()
  3. 10 core/modules/system/src/Form/ThemeSettingsForm.php \Drupal\system\Form\ThemeSettingsForm::submitForm()

Overrides ConfigFormBase::submitForm

File

core/modules/system/src/Form/ThemeSettingsForm.php, line 456

Class

ThemeSettingsForm
Displays theme configuration for entire site and individual themes.

Namespace

Drupal\system\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form, $form_state);
    $config_key = $form_state->getValue('config_key');
    $this->editableConfig = [
        $config_key,
    ];
    $config = $this->config($config_key);
    // Exclude unnecessary elements before saving.
    $form_state->cleanValues();
    $form_state->unsetValue('var');
    $form_state->unsetValue('config_key');
    $values = $form_state->getValues();
    // If the user uploaded a new logo or favicon, save it to a permanent location
    // and use it in place of the default theme-provided file.
    $default_scheme = $this->config('system.file')
        ->get('default_scheme');
    try {
        if (!empty($values['logo_upload'])) {
            $filename = $this->fileSystem
                ->copy($values['logo_upload']->getFileUri(), $default_scheme . '://');
            $values['default_logo'] = 0;
            $values['logo_path'] = $filename;
        }
    } catch (FileException $e) {
        // Ignore.
    }
    try {
        if (!empty($values['favicon_upload'])) {
            $filename = $this->fileSystem
                ->copy($values['favicon_upload']->getFileUri(), $default_scheme . '://');
            $values['default_favicon'] = 0;
            $values['favicon_path'] = $filename;
            $values['toggle_favicon'] = 1;
        }
    } catch (FileException $e) {
        // Ignore.
    }
    unset($values['logo_upload']);
    unset($values['favicon_upload']);
    // If the user entered a path relative to the system files directory for
    // a logo or favicon, store a public:// URI so the theme system can handle it.
    if (!empty($values['logo_path'])) {
        $values['logo_path'] = $this->validatePath($values['logo_path']);
    }
    if (!empty($values['favicon_path'])) {
        $values['favicon_path'] = $this->validatePath($values['favicon_path']);
    }
    if (empty($values['default_favicon']) && !empty($values['favicon_path'])) {
        $values['favicon_mimetype'] = $this->mimeTypeGuesser
            ->guessMimeType($values['favicon_path']);
    }
    theme_settings_convert_to_config($values, $config)->save();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.