You are here

function collapsiblock_form_block_form_alter in Collapsiblock 8

Same name and namespace in other branches
  1. 8.2 collapsiblock.module \collapsiblock_form_block_form_alter()
  2. 4.x collapsiblock.module \collapsiblock_form_block_form_alter()
  3. 3.x collapsiblock.module \collapsiblock_form_block_form_alter()

Implements hook_form_FORM_ID_alter().

File

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

Code

function collapsiblock_form_block_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $default_config = \Drupal::config('collapsiblock.settings');
  if (!empty($form['id']['#default_value'])) {
    $block = Block::load($form['id']['#default_value']);
    if ($block) {
      $default_state = $block
        ->get('collapsiblock');
      $settings['collapse_type'] = $default_state['block-' . str_replace('_', '-', $block
        ->get('id'))];
    }
  }
  $form['collapsiblock_settings'] = [
    '#type' => 'details',
    '#title' => t('Collapsible'),
    '#open' => TRUE,
  ];
  $form['collapsiblock_settings']['collapse_type'] = [
    '#type' => 'radios',
    '#title' => t('Block collapse behavior'),
    '#options' => [
      1 => t('None.'),
      2 => t('Collapsible, expanded by default.'),
      3 => t('Collapsible, collapsed by default.'),
      4 => t('Collapsible, collapsed all the time.'),
    ],
    '#default_value' => !empty($settings['collapse_type']) ? $settings['collapse_type'] : $default_config
      ->get('default_state'),
  ];
  $form['actions']['submit']['#submit'][] = 'collapsiblock_submit';
}