function ThemeSettingsForm::validateForm

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

Overrides FormBase::validateForm

File

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

Class

ThemeSettingsForm
Displays theme configuration for entire site and individual themes.

Namespace

Drupal\system\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
    parent::validateForm($form, $form_state);
    if ($this->moduleHandler
        ->moduleExists('file')) {
        // Check for a new uploaded logo.
        if (isset($form['logo'])) {
            $file = _file_save_upload_from_form($form['logo']['settings']['logo_upload'], $form_state, 0);
            if ($file) {
                // Put the temporary file in form_values so we can save it on submit.
                $form_state->setValue('logo_upload', $file);
            }
        }
        // Check for a new uploaded favicon.
        if (isset($form['favicon'])) {
            $file = _file_save_upload_from_form($form['favicon']['settings']['favicon_upload'], $form_state, 0);
            if ($file) {
                // Put the temporary file in form_values so we can save it on submit.
                $form_state->setValue('favicon_upload', $file);
            }
        }
        // When intending to use the default logo, unset the logo_path.
        if ($form_state->getValue('default_logo')) {
            $form_state->unsetValue('logo_path');
        }
        // When intending to use the default favicon, unset the favicon_path.
        if ($form_state->getValue('default_favicon')) {
            $form_state->unsetValue('favicon_path');
        }
        // If the user provided a path for a logo or favicon file, make sure a file
        // exists at that path.
        if ($form_state->getValue('logo_path')) {
            $path = $this->validatePath($form_state->getValue('logo_path'));
            if (!$path) {
                $form_state->setErrorByName('logo_path', $this->t('The custom logo path is invalid.'));
            }
        }
        if ($form_state->getValue('favicon_path')) {
            $path = $this->validatePath($form_state->getValue('favicon_path'));
            if (!$path) {
                $form_state->setErrorByName('favicon_path', $this->t('The custom favicon path is invalid.'));
            }
        }
    }
}

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