You are here

public function SimplePopupBlocksAddForm::submitForm 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::submitForm()

Form submission handler.

Parameters

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

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

Overrides ConfigFormBase::submitForm

1 call to SimplePopupBlocksAddForm::submitForm()
SimplePopupBlocksEditForm::submitForm in src/Form/SimplePopupBlocksEditForm.php
Form submission handler.
1 method overrides SimplePopupBlocksAddForm::submitForm()
SimplePopupBlocksEditForm::submitForm in src/Form/SimplePopupBlocksEditForm.php
Form submission handler.

File

src/Form/SimplePopupBlocksAddForm.php, line 354

Class

SimplePopupBlocksAddForm
Form to add a popup entry.

Namespace

Drupal\simple_popup_blocks\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  if ($form_state
    ->getValue('type') == 0) {
    $identifier = $form_state
      ->getValue('block_list');
  }
  else {
    $identifier = $form_state
      ->getValue('custom_css');
  }
  $delay = $form_state
    ->getValue('delay');
  if (empty($delay) || $delay < 0) {
    $delay = 0;
  }
  $width = $form_state
    ->getValue('width');
  if (empty($width) || $width < 0) {
    $width = 400;
  }
  $cookie_expiry = $form_state
    ->getValue('cookie_expiry');
  if (strlen($cookie_expiry) == 0 || $cookie_expiry < 0) {
    $cookie_expiry = 100;
  }
  if ($form_state
    ->getValue('use_time_frequency')) {
    $visit_counts = serialize([
      0 => '0',
    ]);
  }
  else {
    $visit_counts = serialize($form_state
      ->getValue('visit_counts'));
  }
  $uid = preg_replace('@[^a-z0-9_]+@', '_', strtolower($form_state
    ->getValue('uid')));
  $config = \Drupal::service('config.factory')
    ->getEditable('simple_popup_blocks.popup_' . $uid);
  $config
    ->set('identifier', $identifier)
    ->set('uid', $uid)
    ->set('type', $form_state
    ->getValue('type'))
    ->set('css_selector', $form_state
    ->getValue('css_selector'))
    ->set('layout', $form_state
    ->getValue('layout'))
    ->set('visit_counts', $visit_counts)
    ->set('overlay', $form_state
    ->getValue('overlay'))
    ->set('trigger_method', $form_state
    ->getValue('trigger_method'))
    ->set('trigger_selector', $form_state
    ->getValue('trigger_selector'))
    ->set('enable_escape', $form_state
    ->getValue('enable_escape'))
    ->set('delay', $delay)
    ->set('minimize', $form_state
    ->getValue('minimize'))
    ->set('close', $form_state
    ->getValue('close'))
    ->set('use_time_frequency', $form_state
    ->getValue('use_time_frequency'))
    ->set('time_frequency', $form_state
    ->getValue('time_frequency'))
    ->set('show_minimized_button', $form_state
    ->getValue('show_minimized_button'))
    ->set('width', $width)
    ->set('cookie_expiry', $cookie_expiry)
    ->set('status', $form_state
    ->getValue('status'))
    ->save();
  parent::submitForm($form, $form_state);
}