public function ScheduleEmailWebformHandler::validateConfigurationForm in Webform 6.x
Same name and namespace in other branches
- 8.5 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 303
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);
$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 = $this->scheduledEmailManager
->getDateFormat();
// Validate custom 'send on' date.
if (WebformDateHelper::createFromFormat($date_format, $values['send']) === FALSE) {
$t_args = [
'%field' => $this
->t('Send on'),
'%format' => $this->scheduledEmailManager
->getDateFormatLabel(),
'@type' => $this->scheduledEmailManager
->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);
}