You are here

function collapsiblock_form_block_form_alter in Collapsiblock 8.2

Same name and namespace in other branches
  1. 8 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 40
Make blocks collapsible.

Code

function collapsiblock_form_block_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $form['collapsiblock_settings'] = [
    '#type' => 'details',
    '#title' => t('Collapsible'),
    '#open' => TRUE,
  ];

  // Add the global default to the list of options for the per-block setting.
  $block = $form_state
    ->getFormObject()
    ->getEntity();
  $options = unserialize(COLLAPSIBLOCK_ACTION_OPTIONS);
  $settings = \Drupal::config('collapsiblock.settings');
  $default_action = $options[$settings
    ->get('default_action')];
  $options = [
    0 => 'Global default, currently set to: ' . $default_action,
  ] + $options;
  $form['collapsiblock_settings']['collapse_action'] = [
    '#type' => 'radios',
    '#title' => t('Block collapse behavior'),
    '#options' => $options,
    '#default_value' => $block
      ->getThirdPartySetting('collapsiblock', 'collapse_action', 0),
  ];
  $form['#entity_builders'][] = 'collapsiblock_block_form_form_builder';
}