theme-settings.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * @file
  4. * Provides an additional config form for theme settings.
  5. */
  6. use Drupal\Core\Form\FormStateInterface;
  7. // Set theme name to use in the key values.
  8. $theme_name = \Drupal::theme()->getActiveTheme()->getName();
  9. /**
  10. * Implements hook_form_system_theme_settings_alter().
  11. *
  12. * Form override for theme settings.
  13. */
  14. function basic_form_system_theme_settings_alter(array &$form, FormStateInterface $form_state) {
  15. $form['options_settings'] = [
  16. '#type' => 'fieldset',
  17. '#title' => t('Theme Specific Settings'),
  18. ];
  19. // BrowserSync support.
  20. $form['options_settings']['basic_browser_sync'] = [
  21. '#type' => 'fieldset',
  22. '#title' => t('BrowserSync Settings'),
  23. ];
  24. $form['options_settings']['basic_browser_sync']['browser_sync']['#tree'] = TRUE;
  25. $form['options_settings']['basic_browser_sync']['browser_sync']['enabled'] = [
  26. '#type' => 'checkbox',
  27. '#title' => t('Enable BrowserSync support for theme'),
  28. '#default_value' => theme_get_setting('browser_sync.enabled'),
  29. '#description' => t("Checking this box will automatically add the BrowserSync JS to your theme for development."),
  30. ];
  31. $form['options_settings']['basic_browser_sync']['browser_sync']['host'] = [
  32. '#type' => 'textfield',
  33. '#title' => t('BrowserSync host'),
  34. '#default_value' => theme_get_setting('browser_sync.host'),
  35. '#description' => t("Default: localhost. Enter 'HOST' which will be replaced by your site's hostname."),
  36. '#states' => [
  37. 'visible' => [':input[name="browser_sync[enabled]"]' => ['checked' => TRUE]],
  38. ],
  39. ];
  40. $form['options_settings']['basic_browser_sync']['browser_sync']['port'] = [
  41. '#type' => 'number',
  42. '#title' => t('Enable BrowserSync support for theme'),
  43. '#default_value' => theme_get_setting('browser_sync.port'),
  44. '#description' => t("Default: '3000'."),
  45. '#states' => [
  46. 'visible' => [':input[name="browser_sync[enabled]"]' => ['checked' => TRUE]],
  47. ],
  48. ];
  49. // IE specific settings.
  50. $form['options_settings']['basic_ie'] = [
  51. '#type' => 'fieldset',
  52. '#title' => t('Internet Explorer Stylesheets'),
  53. ];
  54. $form['options_settings']['basic_ie']['ie_enabled'] = [
  55. '#type' => 'checkbox',
  56. '#title' => t('Enable Internet Explorer stylesheets in theme'),
  57. '#default_value' => theme_get_setting('ie_enabled'),
  58. '#description' => t('If you check this box you can choose which IE stylesheets in theme get rendered on display.'),
  59. ];
  60. $form['options_settings']['basic_ie']['ie_enabled_css'] = [
  61. '#type' => 'fieldset',
  62. '#title' => t('Which IE versions you want to enable ".lt-ie" CSS classes'),
  63. '#states' => [
  64. 'visible' => [':input[name="ie_enabled"]' => ['checked' => TRUE]],
  65. ],
  66. ];
  67. $form['options_settings']['basic_ie']['ie_enabled_css']['ie_enabled_versions'] = [
  68. '#type' => 'checkboxes',
  69. '#options' => [
  70. 'ie8' => t('Internet Explorer 8'),
  71. 'ie9' => t('Internet Explorer 9'),
  72. ],
  73. '#default_value' => array_keys(array_filter(theme_get_setting('ie_enabled_versions'))) ?: [],
  74. ];
  75. }