You are here

public function BootstrapModalMessagesAdminForm::buildForm in Bootstrap Modal Messages 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/BootstrapModalMessagesAdminForm.php, line 32

Class

BootstrapModalMessagesAdminForm
Class BootstrapModalMessagesAdminForm.

Namespace

Drupal\bootstrap_modal_messages\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('bootstrap_modal_messages.settings');
  $form['bootstrap_modal_messages_selector'] = array(
    '#type' => 'textfield',
    '#title' => t('Messages div selector'),
    '#default_value' => \Drupal::config('bootstrap_modal_messages.settings')
      ->get('bootstrap_modal_messages_selector'),
    '#description' => t('The CSS/JS selector to find messages for the modal.'),
  );
  $form['bootstrap_modal_messages_multiple'] = array(
    '#type' => 'select',
    '#title' => t('Multiple messages setting'),
    '#options' => array(
      'single' => t('Single modal'),
      'multiple' => t('Multiple - New modal per message type'),
    ),
    '#default_value' => \Drupal::config('bootstrap_modal_messages.settings')
      ->get('bootstrap_modal_messages_multiple'),
    '#description' => t('How to handle multiple messages on one page?'),
  );
  $form['bootstrap_modal_messages_ignore_admin'] = array(
    '#type' => 'select',
    '#title' => t('Ignore admin pages'),
    '#options' => array(
      1 => t('Yes'),
      0 => t('No'),
    ),
    '#default_value' => \Drupal::config('bootstrap_modal_messages.settings')
      ->get('bootstrap_modal_messages_ignore_admin'),
    '#description' => t('Ignore admin pages so that messages display normally?'),
  );

  // Modal header.
  $form['modal_header'] = array(
    '#type' => 'fieldset',
    '#title' => t('Modal Header'),
    '#collapsible' => TRUE,
  );
  $form['modal_header']['bootstrap_modal_messages_show_header'] = array(
    '#type' => 'select',
    '#title' => t('Show header'),
    '#options' => array(
      1 => t('Yes'),
      0 => t('No'),
    ),
    '#default_value' => \Drupal::config('bootstrap_modal_messages.settings')
      ->get('bootstrap_modal_messages_show_header'),
    '#description' => t('Show the modal header.'),
  );
  $title = $config
    ->get('bootstrap_modal_messages_title');
  $form['modal_header']['bootstrap_modal_messages_title'] = array(
    '#type' => 'text_format',
    '#title' => t('Modal Title'),
    '#default_value' => $title['value'] ?: '',
    '#format' => $title['format'] ?: 'plain_text',
    '#description' => t('Enter text to be used in the modal title. Defaults to "Messages".'),
    '#states' => array(
      'visible' => array(
        ':input[name="bootstrap_modal_messages_show_header"]' => array(
          'value' => 1,
        ),
      ),
    ),
  );
  $form['modal_header']['bootstrap_modal_messages_header_close'] = array(
    '#type' => 'select',
    '#title' => t('Show close button (X)'),
    '#options' => array(
      1 => t('Yes'),
      0 => t('No'),
    ),
    '#default_value' => \Drupal::config('bootstrap_modal_messages.settings')
      ->get('bootstrap_modal_messages_header_close'),
    '#description' => t('Show the close (X) button in modal header.'),
  );

  // Modal footer.
  $form['modal_footer'] = array(
    '#type' => 'fieldset',
    '#title' => t('Modal Footer'),
    '#collapsible' => TRUE,
  );
  $form['modal_footer']['bootstrap_modal_messages_show_footer'] = array(
    '#type' => 'select',
    '#title' => t('Show footer'),
    '#options' => array(
      1 => t('Yes'),
      0 => t('No'),
    ),
    '#default_value' => \Drupal::config('bootstrap_modal_messages.settings')
      ->get('bootstrap_modal_messages_show_footer'),
    '#description' => t('Show the modal footer.'),
  );
  $footer = $config
    ->get('bootstrap_modal_messages_footer_html');
  $form['modal_footer']['bootstrap_modal_messages_footer_html'] = array(
    '#type' => 'text_format',
    '#title' => t('Footer HTML'),
    '#default_value' => $footer['value'] ?: '',
    '#format' => $footer['format'] ?: 'plain_text',
    '#description' => t("Enter text to be displayed in the footer. Leave empty to use Bootstrap's default Close button."),
    '#states' => array(
      'visible' => array(
        ':input[name="bootstrap_modal_messages_show_footer"]' => array(
          'value' => 1,
        ),
      ),
    ),
  );

  // Modal controls.
  $form['controls'] = array(
    '#type' => 'fieldset',
    '#title' => t('Controls'),
    '#collapsible' => TRUE,
  );
  $form['controls']['bootstrap_modal_messages_show_onload'] = array(
    '#type' => 'select',
    '#title' => t('Open modal on page load?'),
    '#options' => array(
      1 => t('Yes'),
      0 => t('No - Should enable "Show controls" to display modal'),
    ),
    '#default_value' => \Drupal::config('bootstrap_modal_messages.settings')
      ->get('bootstrap_modal_messages_show_onload'),
    '#description' => t('Open modal immediately when the page loads.'),
  );
  $form['controls']['bootstrap_modal_messages_onload_expiration'] = array(
    '#type' => 'number',
    '#title' => t('Time (in seconds) browser waits to display messages again.'),
    '#min' => 0,
    '#max' => 86400,
    '#default_value' => \Drupal::config('bootstrap_modal_messages.settings')
      ->get('bootstrap_modal_messages_onload_expiration'),
    '#description' => t('Upon subsequent page loads, the "show onload" will not happen until this time has elapsed. Useful for single, sitewide messages.'),
    '#states' => array(
      'visible' => array(
        ':input[name="bootstrap_modal_messages_show_onload"]' => array(
          'value' => 1,
        ),
      ),
    ),
  );
  $form['controls']['bootstrap_modal_messages_show_controls'] = array(
    '#type' => 'select',
    '#title' => t('Show controls?'),
    '#options' => array(
      0 => t('No'),
      1 => t('Yes'),
    ),
    '#default_value' => \Drupal::config('bootstrap_modal_messages.settings')
      ->get('bootstrap_modal_messages_show_controls'),
    '#description' => t('Creates a div that allows you to show messages again. <strong>This setting can be overridden by the permission "View Bootstrap Modal Messages controls".</strong>'),
  );
  $controls = $config
    ->get('bootstrap_modal_messages_controls_html');
  $form['controls']['bootstrap_modal_messages_controls_html'] = array(
    '#type' => 'text_format',
    '#title' => t('Controls HTML'),
    '#default_value' => $controls['value'] ?: '',
    '#format' => $controls['format'] ?: 'plain_text',
    '#description' => t('Enter the HTML to be used in the div for controls.'),
    '#states' => array(
      'visible' => array(
        ':input[name="bootstrap_modal_messages_show_controls"]' => array(
          'value' => 1,
        ),
      ),
    ),
  );
  return parent::buildForm($form, $form_state);
}