You are here

public function BetterMessagesSettingsForm::buildForm in Better 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/BetterMessagesSettingsForm.php, line 70

Class

BetterMessagesSettingsForm
Admin settings form of the module.

Namespace

Drupal\better_messages\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('better_messages.settings');
  $form_state
    ->setTemporaryValue('gathered_contexts', $this->contextRepository
    ->getAvailableContexts());
  $settings = $config
    ->get();
  $form['position'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Messages positions and basic properties'),
    '#weight' => -5,
    '#open' => TRUE,
  ];
  $form['position']['pos'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Set position of Message'),
    '#default_value' => $settings['position'],
    '#description' => $this
      ->t('Position of message relative to screen'),
    '#attributes' => [
      'class' => [
        'better-messages-admin-radios',
      ],
    ],
    '#options' => [
      'center' => $this
        ->t('Center screen'),
      'tl' => $this
        ->t('Top left'),
      'tr' => $this
        ->t('Top right'),
      'bl' => $this
        ->t('Bottom left'),
      'br' => $this
        ->t('Bottom right'),
    ],
  ];
  $form['position']['fixed'] = [
    '#type' => 'checkbox',
    '#default_value' => $settings['fixed'],
    '#title' => $this
      ->t('Keep fixed position of message as you scroll.'),
  ];
  $form['position']['width'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Custom width'),
    '#description' => $this
      ->t('Width in pixel (e.g. 400px) or percentage (e.g. 100%). Leave empty if you prefer your theme to control the width.'),
    '#default_value' => $settings['width'],
    '#size' => 20,
    '#maxlength' => 20,
  ];
  $form['position']['horizontal'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Left/Right spacing'),
    '#default_value' => $settings['horizontal'],
    '#size' => 20,
    '#maxlength' => 20,
    '#required' => TRUE,
    '#field_suffix' => $this
      ->t('px'),
    '#states' => [
      'invisible' => [
        ':input[name="pos"]' => [
          'value' => 'center',
        ],
      ],
    ],
  ];
  $form['position']['vertical'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Top/Down spacing'),
    '#default_value' => $settings['vertical'],
    '#size' => 20,
    '#maxlength' => 20,
    '#required' => TRUE,
    '#field_suffix' => $this
      ->t('px'),
    '#states' => [
      'invisible' => [
        ':input[name="pos"]' => [
          'value' => 'center',
        ],
      ],
    ],
  ];
  $form['animation'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Messages animation settings'),
    '#weight' => -3,
    '#open' => TRUE,
  ];
  $form['animation']['popin_effect'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Pop-in (show) message box effect'),
    '#default_value' => $settings['popin']['effect'],
    '#options' => [
      'fadeIn' => $this
        ->t('Fade in'),
      'slideDown' => $this
        ->t('Slide down'),
    ],
  ];
  $form['animation']['popin_duration'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Duration of (show) effect'),
    '#description' => $this
      ->t('A string representing one of the three predefined speeds ("slow", "normal", or "fast").<br />Or the number of milliseconds to run the animation (e.g. 1000).'),
    '#default_value' => $settings['popin']['duration'],
    '#size' => 20,
    '#maxlength' => 20,
  ];
  $form['animation']['popout_effect'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Pop-out (close) message box effect'),
    '#default_value' => $settings['popout']['effect'],
    '#options' => [
      'fadeIn' => $this
        ->t('Fade out'),
      'slideUp' => $this
        ->t('Slide Up'),
    ],
  ];
  $form['animation']['popout_duration'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Duration of (close) effect'),
    '#description' => $this
      ->t('A string representing one of the three predefined speeds ("slow", "normal", or "fast").<br />Or the number of milliseconds to run the animation (e.g. 1000).'),
    '#default_value' => $settings['popout']['duration'],
    '#size' => 20,
    '#maxlength' => 20,
  ];
  $form['animation']['autoclose'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Number of seconds to auto close after the page has loaded'),
    '#description' => $this
      ->t('0 for never. You can set it as 0.25 for quarter second'),
    '#default_value' => $settings['autoclose'],
    '#size' => 20,
    '#maxlength' => 20,
  ];
  $form['animation']['disable_autoclose'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Disable auto close if messages include an error message'),
    '#default_value' => $settings['disable_autoclose'],
  ];
  $form['animation']['show_countdown'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show countdown timer'),
    '#default_value' => $settings['show_countdown'],
  ];
  $form['animation']['hover_autoclose'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Stop auto close timer when hover'),
    '#default_value' => $settings['hover_autoclose'],
  ];
  $form['animation']['open_delay'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Number of seconds to delay message after the page has loaded'),
    '#description' => $this
      ->t('0 for never. You can set it as 0.25 for quarter second'),
    '#default_value' => $settings['opendelay'],
    '#size' => 20,
    '#maxlength' => 20,
  ];
  $form['jquery_ui'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('jQuery UI enhancements'),
    '#weight' => 10,
    '#description' => $this
      ->t('These settings require jQuery UI.'),
    '#open' => TRUE,
  ];
  $form['jquery_ui']['draggable'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Make Better Messages draggable'),
    '#default_value' => $settings['jquery_ui']['draggable'],
  ];
  $form['jquery_ui']['resizable'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Make Better Messages resizable'),
    '#default_value' => $settings['jquery_ui']['resizable'],
  ];
  $form['visibility'] = $this
    ->buildVisibility([], $form_state);
  return parent::buildForm($form, $form_state);
}