public function SmartDateOverrideForm::ajaxSubmit in Smart Date 3.0.x
Same name and namespace in other branches
- 8.2 modules/smart_date_recur/src/Form/SmartDateOverrideForm.php \Drupal\smart_date_recur\Form\SmartDateOverrideForm::ajaxSubmit()
- 3.x modules/smart_date_recur/src/Form/SmartDateOverrideForm.php \Drupal\smart_date_recur\Form\SmartDateOverrideForm::ajaxSubmit()
- 3.1.x modules/smart_date_recur/src/Form/SmartDateOverrideForm.php \Drupal\smart_date_recur\Form\SmartDateOverrideForm::ajaxSubmit()
- 3.2.x modules/smart_date_recur/src/Form/SmartDateOverrideForm.php \Drupal\smart_date_recur\Form\SmartDateOverrideForm::ajaxSubmit()
- 3.3.x modules/smart_date_recur/src/Form/SmartDateOverrideForm.php \Drupal\smart_date_recur\Form\SmartDateOverrideForm::ajaxSubmit()
- 3.4.x modules/smart_date_recur/src/Form/SmartDateOverrideForm.php \Drupal\smart_date_recur\Form\SmartDateOverrideForm::ajaxSubmit()
Ajax submit function.
Parameters
array $form: The render array of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The form state to submit.
Return value
\Drupal\Core\Ajax\AjaxResponse The return value of the AJAX submission.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
File
- modules/
smart_date_recur/ src/ Form/ SmartDateOverrideForm.php, line 142
Class
- SmartDateOverrideForm
- Form controller for Smart Date Recur instace override edit forms.
Namespace
Drupal\smart_date_recur\FormCode
public function ajaxSubmit(array &$form, FormStateInterface $form_state) {
$response = new AjaxResponse();
$status_messages = [
'#type' => 'status_messages',
];
$messages = \Drupal::service('renderer')
->renderRoot($status_messages);
if (!empty($messages)) {
$response
->addCommand(new RemoveCommand('.messages-list'));
$response
->addCommand(new PrependCommand('#manage-instances', $messages));
return $response;
}
$form_state
->disableRedirect();
/* @var \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager */
$entityTypeManager = \Drupal::service('entity_type.manager');
/* @var \Drupal\smart_date_recur\Entity\SmartDateRule $rrule */
$rrule = $entityTypeManager
->getStorage('smart_date_rule')
->load($form_state
->getValue('rrule'));
$instanceController = new Instances();
$instanceController
->setSmartDateRule($rrule);
$instanceController
->setUseAjax(TRUE);
$response = new AjaxResponse();
$response
->addCommand(new ReplaceCommand('#manage-instances', $instanceController
->listInstancesOutput()));
return $response;
}