ThemeAdminForm.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace Drupal\system\Form;
  3. use Drupal\Core\Form\ConfigFormBase;
  4. use Drupal\Core\Form\FormStateInterface;
  5. /**
  6. * Form to select the administration theme.
  7. *
  8. * @internal
  9. */
  10. class ThemeAdminForm extends ConfigFormBase {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function getFormId() {
  15. return 'system_themes_admin_form';
  16. }
  17. /**
  18. * {@inheritdoc}
  19. */
  20. protected function getEditableConfigNames() {
  21. return ['system.theme'];
  22. }
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function buildForm(array $form, FormStateInterface $form_state, array $theme_options = NULL) {
  27. // Administration theme settings.
  28. $form['admin_theme'] = [
  29. '#type' => 'details',
  30. '#title' => $this->t('Administration theme'),
  31. '#open' => TRUE,
  32. ];
  33. $form['admin_theme']['admin_theme'] = [
  34. '#type' => 'select',
  35. '#options' => [0 => $this->t('Default theme')] + $theme_options,
  36. '#title' => $this->t('Administration theme'),
  37. '#description' => $this->t('Choose "Default theme" to always use the same theme as the rest of the site.'),
  38. '#default_value' => $this->config('system.theme')->get('admin'),
  39. ];
  40. $form['admin_theme']['actions'] = ['#type' => 'actions'];
  41. $form['admin_theme']['actions']['submit'] = [
  42. '#type' => 'submit',
  43. '#value' => $this->t('Save configuration'),
  44. '#button_type' => 'primary',
  45. ];
  46. return $form;
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function submitForm(array &$form, FormStateInterface $form_state) {
  52. parent::submitForm($form, $form_state);
  53. $this->config('system.theme')->set('admin', $form_state->getValue('admin_theme'))->save();
  54. }
  55. }