You are here

function browsersync_form_system_theme_settings_alter in Browsersync 8

Same name and namespace in other branches
  1. 8.2 browsersync.module \browsersync_form_system_theme_settings_alter()
  2. 7 browsersync.module \browsersync_form_system_theme_settings_alter()

Implements hook_form_FORM_ID_alter().

Adds the Browsersync configuration options to the theme settings form.

See also

\Drupal\system\Form\ThemeSettingsForm

File

./browsersync.module, line 66
Code for the Browsersync module.

Code

function browsersync_form_system_theme_settings_alter(&$form, FormStateInterface $form_state) {

  // Extract the theme key from the form arguments. If not present, it means
  // that we are altering the global theme settings form.
  $args = $form_state
    ->getBuildInfo()['args'];
  $theme_key = !empty($args[0]) ? $args[0] : NULL;
  $form['browsersync'] = [
    '#type' => 'details',
    '#title' => 'Browsersync settings',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  ];
  $form['browsersync']['browsersync_enabled'] = [
    '#title' => 'Enable Browsersync',
    '#type' => 'checkbox',
    '#default_value' => browsersync_get_setting('enabled', $theme_key),
  ];
  $form['browsersync']['settings'] = [
    '#type' => 'container',
    '#states' => [
      'visible' => [
        'input[name="browsersync_enabled"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['browsersync']['settings']['browsersync_host'] = [
    '#title' => 'Host',
    '#type' => 'textfield',
    '#description' => t('Override host detection if you know the correct IP to use.'),
    '#default_value' => browsersync_get_setting('host', $theme_key),
  ];
  $form['browsersync']['settings']['browsersync_port'] = [
    '#title' => 'Port',
    '#type' => 'textfield',
    '#description' => t('Use a specific port (instead of the one auto-detected by Browsersync).'),
    '#default_value' => browsersync_get_setting('port', $theme_key),
  ];
  $form['#submit'][] = 'browsersync_theme_settings_form_submit';
}