You are here

function collapsiblock_form_system_theme_settings_alter in Collapsiblock 8

Implements hook_form_system_theme_settings_alter().

File

./collapsiblock.module, line 96
Make blocks collapsible.

Code

function collapsiblock_form_system_theme_settings_alter(&$form, FormStateInterface $form_state) {
  $default_config = \Drupal::config('collapsiblock.settings');
  $build_info = $form_state
    ->getBuildInfo();
  $theme_name = $build_info['args'][0];

  // Add new fields for default settings.
  $form['collapsiblock'] = [
    '#type' => 'details',
    '#title' => t('Collapsiblock selectors'),
    '#open' => TRUE,
    '#description' => t("Force <a href='http://api.jquery.com/category/selectors/'>CSS selector</a> if collapsiblock doesn't work out of the box"),
    '#weight' => 0,
    '#attributes' => [
      'id' => 'collapsiblock_form',
    ],
  ];
  $form['collapsiblock']['collapsiblock_block'] = [
    '#type' => 'textfield',
    '#title' => t('Block'),
    '#default_value' => !empty(theme_get_setting('collapsiblock_block', $theme_name)) ? theme_get_setting('collapsiblock_block', $theme_name) : $default_config
      ->get('block'),
  ];
  $form['collapsiblock']['collapsiblock_title'] = [
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => !empty(theme_get_setting('collapsiblock_title', $theme_name)) ? theme_get_setting('collapsiblock_title', $theme_name) : $default_config
      ->get('title'),
  ];
  $form['collapsiblock']['collapsiblock_content'] = [
    '#type' => 'textfield',
    '#title' => t('Block content'),
    '#default_value' => !empty(theme_get_setting('collapsiblock_content', $theme_name)) ? theme_get_setting('collapsiblock_content', $theme_name) : $default_config
      ->get('content'),
  ];
}