public ThemeSettingsForm::validateForm(array &$form, FormStateInterface $form_state)
Form validation 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 FormBase::validateForm
File
- core/modules/system/src/Form/ThemeSettingsForm.php, line 344
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')) {
// Handle file uploads.
$validators = array('file_validate_is_image' => array());
// Check for a new uploaded logo.
$file = file_save_upload('logo_upload', $validators, FALSE, 0);
if (isset($file)) {
// File upload was attempted.
if ($file) {
// Put the temporary file in form_values so we can save it on submit.
$form_state->setValue('logo_upload', $file);
}
else {
// File upload failed.
$form_state->setErrorByName('logo_upload', $this->t('The logo could not be uploaded.'));
}
}
$validators = array('file_validate_extensions' => array('ico png gif jpg jpeg apng svg'));
// Check for a new uploaded favicon.
$file = file_save_upload('favicon_upload', $validators, FALSE, 0);
if (isset($file)) {
// File upload was attempted.
if ($file) {
// Put the temporary file in form_values so we can save it on submit.
$form_state->setValue('favicon_upload', $file);
}
else {
// File upload failed.
$form_state->setErrorByName('favicon_upload', $this->t('The favicon could not be uploaded.'));
}
}
// 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.'));
}
}
}
}
Please login to continue.