public function ScheduleEmailWebformHandler::validateConfigurationForm in Webform 8.5
Same name and namespace in other branches
- 6.x modules/webform_scheduled_email/src/Plugin/WebformHandler/ScheduleEmailWebformHandler.php \Drupal\webform_scheduled_email\Plugin\WebformHandler\ScheduleEmailWebformHandler::validateConfigurationForm()
Form validation handler.
Parameters
array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().
Overrides EmailWebformHandler::validateConfigurationForm
File
- modules/
webform_scheduled_email/ src/ Plugin/ WebformHandler/ ScheduleEmailWebformHandler.php, line 284
Class
- ScheduleEmailWebformHandler
- Schedules a webform submission's email.
Namespace
Drupal\webform_scheduled_email\Plugin\WebformHandlerCode
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::validateConfigurationForm($form, $form_state);
/** @var \Drupal\webform_scheduled_email\WebformScheduledEmailManagerInterface $webform_scheduled_email_manager */
$webform_scheduled_email_manager = \Drupal::service('webform_scheduled_email.manager');
$values = $form_state
->getValues();
// Cast days string to int.
$values['days'] = (int) $values['days'];
// If token skip validation.
if (!preg_match('/^\\[[^]]+\\]$/', $values['send'])) {
$date_format = $webform_scheduled_email_manager
->getDateFormat();
// Validate custom 'send on' date.
if (WebformDateHelper::createFromFormat($date_format, $values['send']) === FALSE) {
$t_args = [
'%field' => $this
->t('Send on'),
'%format' => $webform_scheduled_email_manager
->getDateFormatLabel(),
'@type' => $webform_scheduled_email_manager
->getDateTypeLabel(),
];
$form_state
->setError($form['settings']['scheduled']['send'], $this
->t('The %field date is required. Please enter a @type in the format %format.', $t_args));
}
}
$form_state
->setValues($values);
}