public function SimplePopupBlocksAddForm::submitForm in Simple Popup Blocks 8
Same name and namespace in other branches
- 8.2 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 FormInterface::submitForm
1 method overrides SimplePopupBlocksAddForm::submitForm()
- SimplePopupBlocksEditForm::submitForm in src/
Form/ SimplePopupBlocksEditForm.php - Form submission handler.
File
- src/
Form/ SimplePopupBlocksAddForm.php, line 293
Class
- SimplePopupBlocksAddForm
- Form to add a popup entry.
Namespace
Drupal\simple_popup_blocks\FormCode
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');
}
$visit_counts = serialize($form_state
->getValue('visit_counts'));
$delay = $form_state
->getValue('delay');
if (empty($delay) || $delay < 0) {
$delay = 0;
}
$width = $form_state
->getValue('width');
if (empty($width) || $width < 0) {
$width = 400;
}
// Save the submitted entry.
$entry = [
'identifier' => $identifier,
'type' => $form_state
->getValue('type'),
'css_selector' => $form_state
->getValue('css_selector'),
'layout' => $form_state
->getValue('layout'),
'visit_counts' => $visit_counts,
'overlay' => $form_state
->getValue('overlay'),
'trigger_method' => $form_state
->getValue('trigger_method'),
'trigger_selector' => $form_state
->getValue('trigger_selector'),
'escape' => $form_state
->getValue('escape'),
'delay' => $delay,
'minimize' => $form_state
->getValue('minimize'),
'close' => $form_state
->getValue('close'),
'width' => $width,
'status' => 1,
];
$return = SimplePopupBlocksStorage::insert($entry, $this->database, $this->messenger);
if ($return) {
$this->messenger
->addMessage($this
->t('Popup settings has been created Successfully. Please place the css code mentioned below under the ADJUSTMENT CLASS Section.'));
$url = Url::fromRoute('simple_popup_blocks.edit')
->setRouteParameters([
'first' => $return,
]);
$form_state
->setRedirectUrl($url);
}
else {
$this->messenger
->addError($this
->t('Error while creating.'));
}
}