public function AdminCssEditor::submitForm in Admin CSS 8.2
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 ConfigFormBase::submitForm
File
- src/
Form/ AdminCssEditor.php, line 134
Class
- AdminCssEditor
- Admin CSS editor form.
Namespace
Drupal\admincss\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('admincss.settings');
$custom_css = $form_state
->getValue('custom_css');
$config
->set('custom_css', $custom_css);
$config
->save();
$changed = FALSE;
$destination_uri = 'public://admin-style.css';
if (empty($custom_css)) {
// Empty CSS, delete the file.
try {
$this->fileSystem
->delete($destination_uri);
$changed = TRUE;
} catch (FileException $e) {
// Ignore and continue.
}
}
elseif (file_save_data($custom_css, $destination_uri, FileSystemInterface::EXISTS_REPLACE)) {
$changed = TRUE;
}
if ($changed) {
// Flush the css/js asset cache.
$this
->flushAssetCache();
}
else {
$this
->messenger()
->addWarning($this
->t('Failed to successfully write the changes to disk.'));
}
parent::submitForm($form, $form_state);
}