public function UserRestrictionsFormBase::validateForm in User restrictions 8
Form validation 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 FormBase::validateForm
File
- src/
Form/ UserRestrictionsFormBase.php, line 119
Class
- UserRestrictionsFormBase
- Base form for image style add and edit forms.
Namespace
Drupal\user_restrictions\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
// Check for duplicate pattern.
$existing = $this->entityTypeManager
->getStorage('user_restrictions')
->loadByProperties([
'rule_type' => $form_state
->getValue('rule_type'),
'pattern' => $form_state
->getValue('pattern'),
]);
if (!empty($existing)) {
$form_state
->setError($form['pattern'], $this
->t('A rule with the same pattern already exists.'));
}
// Store the expiration time as unixtime as configuration entities may
// only use scalar values.
/* @var $datetime DrupalDateTime */
$datetime = $form_state
->getValue('expiry');
if ($form_state
->getValue('permanent')) {
$form_state
->setValue('expiry', UserRestrictions::NO_EXPIRY);
}
else {
$form_state
->setValue('expiry', (int) $datetime
->format('U'));
}
parent::validateForm($form, $form_state);
}