public function MaestroReassign::validateForm in Maestro 3.x
Same name and namespace in other branches
- 8.2 src/Form/MaestroReassign.php \Drupal\maestro\Form\MaestroReassign::validateForm()
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/ MaestroReassign.php, line 124
Class
- MaestroReassign
- The Maestro Reassign form.
Namespace
Drupal\maestro\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
// Based on the assignment type, we must validate the form to ensure either the user or role has been entered, and that it's valid.
// if the assign type is anything but the role or user, we offload to other modules to handle.
$assign_type = $form_state
->getValue('assign_type');
if ($assign_type == 'user') {
$user = $form_state
->getValue('select_assigned_user');
if (!isset($user)) {
$form_state
->setErrorByName('select_assigned_user', $this
->t('You must choose a user to reassign to'));
}
}
elseif ($assign_type == 'role') {
$role = $form_state
->getValue('select_assigned_role');
if (!isset($role)) {
$form_state
->setErrorByName('select_assigned_role', $this
->t('You must choose a role to reassign to'));
}
}
else {
// TODO: offload to module to do validation of whatever assign type this is.
}
}