You are here

public function SimplePopupBlocksAddForm::buildForm in Simple Popup Blocks 8

Same name and namespace in other branches
  1. 8.2 src/Form/SimplePopupBlocksAddForm.php \Drupal\simple_popup_blocks\Form\SimplePopupBlocksAddForm::buildForm()

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 FormInterface::buildForm

1 call to SimplePopupBlocksAddForm::buildForm()
SimplePopupBlocksEditForm::buildForm in src/Form/SimplePopupBlocksEditForm.php
Form constructor.
1 method overrides SimplePopupBlocksAddForm::buildForm()
SimplePopupBlocksEditForm::buildForm in src/Form/SimplePopupBlocksEditForm.php
Form constructor.

File

src/Form/SimplePopupBlocksAddForm.php, line 78

Class

SimplePopupBlocksAddForm
Form to add a popup entry.

Namespace

Drupal\simple_popup_blocks\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $visit_counts = [];
  $block_ids = $this->typeManager
    ->getStorage('block')
    ->getQuery()
    ->execute();
  $form = [];
  for ($i = 0; $i < 101; $i++) {
    $visit_counts[] = $i;
  }
  $form['type'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Choose the identifier'),
    '#default_value' => 0,
    '#options' => [
      0 => $this
        ->t('Drupal blocks'),
      1 => $this
        ->t('Custom css id or class'),
    ],
  ];
  $form['block_list'] = [
    '#type' => 'select',
    '#title' => t("Blocks list"),
    '#options' => $block_ids,
    '#states' => [
      'visible' => [
        ':input[name="type"]' => [
          'value' => 0,
        ],
      ],
    ],
  ];
  $form['custom_css'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Selectors without # or .'),
    '#default_value' => t("custom-css-id"),
    '#description' => $this
      ->t("Ex: my-profile, custom_div_cls, someclass, mypopup-class."),
    '#states' => [
      'visible' => [
        ':input[name="type"]' => [
          'value' => 1,
        ],
      ],
    ],
  ];
  $form['css_selector'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Css selector'),
    '#default_value' => 1,
    '#options' => [
      0 => $this
        ->t('Css class (.)'),
      1 => $this
        ->t('Css id (#)'),
    ],
    '#states' => [
      'visible' => [
        ':input[name="type"]' => [
          'value' => 1,
        ],
      ],
    ],
  ];
  $form['layout'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Choose layout'),
    '#default_value' => 0,
    '#options' => [
      0 => $this
        ->t('Top left'),
      1 => $this
        ->t('Top Right'),
      2 => $this
        ->t('Bottom left'),
      3 => $this
        ->t('Bottom Right'),
      4 => $this
        ->t('Center'),
      5 => $this
        ->t('Top center'),
      6 => $this
        ->t('Top bar'),
      7 => $this
        ->t('Bottom bar'),
      8 => $this
        ->t('Left bar'),
      9 => $this
        ->t('Right bar'),
    ],
  ];
  $form['visit_counts'] = [
    '#title' => $this
      ->t('Visit counts'),
    '#type' => 'select',
    '#multiple' => TRUE,
    '#required' => TRUE,
    '#size' => 8,
    '#options' => $visit_counts,
    '#default_value' => 0,
    '#description' => $this
      ->t("Examples:<br>\n        0 = Show popup on users each visit<br> \n        1,2 = Show popup on users first and second visit<br>\n        1,4,7 = Show popup on users first, forth and seventh visit"),
  ];
  $form['minimize'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Minimize button'),
    '#default_value' => 1,
  ];
  $form['close'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Close button'),
    '#default_value' => 1,
  ];
  $form['escape'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('ESC key to close'),
    '#default_value' => 1,
  ];
  $form['overlay'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Overlay'),
    '#default_value' => 1,
  ];
  $form['trigger_method'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Trigger method'),
    '#default_value' => 0,
    '#options' => [
      0 => $this
        ->t('Automatic'),
      1 => $this
        ->t('Manual - on click event'),
      2 => $this
        ->t('Before browser/tab close'),
    ],
  ];
  $form['delay'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Delays'),
    '#size' => 5,
    '#default_value' => 0,
    '#description' => $this
      ->t("Show popup after this seconds. 0 will show immediately after the page load."),
    '#states' => [
      'visible' => [
        ':input[name="trigger_method"]' => [
          'value' => 0,
        ],
      ],
    ],
  ];
  $form['trigger_selector'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Add css id or class starting with # or .'),
    '#default_value' => t("#custom-css-id"),
    '#description' => $this
      ->t("Ex: #my-profile, #custom_div_cls, .someclass, .mypopup-class."),
    '#states' => [
      'visible' => [
        ':input[name="trigger_method"]' => [
          'value' => 1,
        ],
      ],
    ],
  ];
  $form['width'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Width'),
    '#default_value' => 400,
    '#description' => $this
      ->t("Add popup width in pixels"),
  ];
  $form['adjustments'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Adjustment class'),
    '#open' => TRUE,
    '#description' => $this
      ->t("Once you created, you can see the css selectors to customize the popup designs."),
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Convert to popup'),
  ];
  return $form;
}