You are here

public function SimplePopupBlocksAddForm::buildForm in Simple Popup Blocks 8.2

Same name and namespace in other branches
  1. 8 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 ConfigFormBase::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 87

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['uid'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Unique identifier'),
    '#required' => TRUE,
  ];
  $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['popup_frequency'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Popup Frequency'),
  ];
  $form['popup_frequency']['use_time_frequency'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Use time frequency instead of visit count'),
    '#default_value' => 0,
  ];
  $form['popup_frequency']['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"),
    '#states' => [
      'invisible' => [
        ':input[name="use_time_frequency"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['popup_frequency']['time_frequency'] = [
    '#title' => $this
      ->t('Time frequency'),
    '#type' => 'select',
    '#required' => TRUE,
    '#options' => [
      3600 => 'Hourly',
      86400 => 'Daily',
      604800 => 'Weekly',
    ],
    '#default_value' => 3600,
    '#description' => $this
      ->t("Choose frequency popup is displayed to the visitor"),
    '#states' => [
      'visible' => [
        ':input[name="use_time_frequency"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $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['button_configuration']['show_minimized_button'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show minimized button when popup is not automatically triggered'),
    '#default_value' => 0,
  ];
  $form['enable_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_width'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Trigger width'),
    '#size' => 5,
    '#default_value' => "",
    '#description' => $this
      ->t("Specify a pixel width at which the popup should trigger, or leave blank for all widths. Example: 800."),
  ];
  $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['cookie_expiry'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Cookie expiry'),
    '#size' => 5,
    '#default_value' => 100,
    '#description' => $this
      ->t("Delete the cookie after x days. Choose 0 to delete the cookie after the browser closes."),
  ];
  $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('Save Popup'),
  ];
  return $form;
}