You are here

public function SimplePopupBlocksEditForm::submitForm in Simple Popup Blocks 8.2

Same name and namespace in other branches
  1. 8 src/Form/SimplePopupBlocksEditForm.php \Drupal\simple_popup_blocks\Form\SimplePopupBlocksEditForm::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 SimplePopupBlocksAddForm::submitForm

File

src/Form/SimplePopupBlocksEditForm.php, line 183

Class

SimplePopupBlocksEditForm
Form to add a database entry, with all the interesting fields.

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;
  }
  $trigger_width = $form_state
    ->getValue('trigger_width');
  if (empty($trigger_width) || $trigger_width < 0) {
    $trigger_width = NULL;
  }
  $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'));
  }
  $config = \Drupal::service('config.factory')
    ->getEditable('simple_popup_blocks.popup_' . $form_state
    ->getValue('uid'));
  $config
    ->set('identifier', $identifier)
    ->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('trigger_width', $trigger_width)
    ->set('minimize', $form_state
    ->getValue('minimize'))
    ->set('close', $form_state
    ->getValue('close'))
    ->set('width', $width)
    ->set('cookie_expiry', $cookie_expiry)
    ->set('status', $form_state
    ->getValue('status'))
    ->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'))
    ->save();
  parent::submitForm($form, $form_state);
}