public function ThemeExperimentalConfirmForm::submitForm in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/src/Form/ThemeExperimentalConfirmForm.php \Drupal\system\Form\ThemeExperimentalConfirmForm::submitForm()
- 9 core/modules/system/src/Form/ThemeExperimentalConfirmForm.php \Drupal\system\Form\ThemeExperimentalConfirmForm::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
File
- core/
modules/ system/ src/ Form/ ThemeExperimentalConfirmForm.php, line 135
Class
- ThemeExperimentalConfirmForm
- Builds a confirmation form for enabling experimental themes.
Namespace
Drupal\system\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$args = $form_state
->getBuildInfo()['args'];
$theme = $args[0] ?? NULL;
$set_default = $args[1] ?? FALSE;
$themes = $this->themeList
->getList();
$config = $this
->configFactory()
->getEditable('system.theme');
try {
if ($this->themeInstaller
->install([
$theme,
])) {
if ($set_default) {
// Set the default theme.
$config
->set('default', $theme)
->save();
// The status message depends on whether an admin theme is currently
// in use: an empty string means the admin theme is set to be the
// default theme.
$admin_theme = $config
->get('admin');
if (!empty($admin_theme) && $admin_theme !== $theme) {
$this
->messenger()
->addStatus($this
->t('Please note that the administration theme is still set to the %admin_theme theme; consequently, the theme on this page remains unchanged. All non-administrative sections of the site, however, will show the selected %selected_theme theme by default.', [
'%admin_theme' => $themes[$admin_theme]->info['name'],
'%selected_theme' => $themes[$theme]->info['name'],
]));
}
else {
$this
->messenger()
->addStatus($this
->t('%theme is now the default theme.', [
'%theme' => $themes[$theme]->info['name'],
]));
}
}
else {
$this
->messenger()
->addStatus($this
->t('The %theme theme has been installed.', [
'%theme' => $themes[$theme]->info['name'],
]));
}
}
else {
$this
->messenger()
->addError($this
->t('The %theme theme was not found.', [
'%theme' => $theme,
]));
}
} catch (PreExistingConfigException $e) {
$config_objects = $e
->flattenConfigObjects($e
->getConfigObjects());
$this
->messenger()
->addError($this
->formatPlural(count($config_objects), 'Unable to install @extension, %config_names already exists in active configuration.', 'Unable to install @extension, %config_names already exist in active configuration.', [
'%config_names' => implode(', ', $config_objects),
'@extension' => $theme,
]));
} catch (UnmetDependenciesException $e) {
$this
->messenger()
->addError($e
->getTranslatedMessage($this
->getStringTranslation(), $theme));
}
$form_state
->setRedirectUrl($this
->getCancelUrl());
}