public function WorkflowTransitionAddForm::validateForm in Drupal 10
Same name and namespace in other branches
- 8 core/modules/workflows/src/Form/WorkflowTransitionAddForm.php \Drupal\workflows\Form\WorkflowTransitionAddForm::validateForm()
- 9 core/modules/workflows/src/Form/WorkflowTransitionAddForm.php \Drupal\workflows\Form\WorkflowTransitionAddForm::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
- core/
modules/ workflows/ src/ Form/ WorkflowTransitionAddForm.php, line 150
Class
- WorkflowTransitionAddForm
- Entity form variant for adding workflow transitions.
Namespace
Drupal\workflows\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\workflows\WorkflowInterface $workflow */
$workflow = $this
->getEntity();
$workflow_type = $workflow
->getTypePlugin();
$values = $form_state
->getValues();
foreach (array_filter($values['from']) as $from_state_id) {
if ($workflow
->getTypePlugin()
->hasTransitionFromStateToState($from_state_id, $values['to'])) {
$form_state
->setErrorByName('from][' . $from_state_id, $this
->t('The transition from %from to %to already exists.', [
'%from' => $workflow
->getTypePlugin()
->getState($from_state_id)
->label(),
'%to' => $workflow
->getTypePlugin()
->getState($values['to'])
->label(),
]));
}
}
if ($workflow_type
->hasFormClass(TransitionInterface::PLUGIN_FORM_KEY)) {
$subform_state = SubformState::createForSubform($form['type_settings'], $form, $form_state);
$this->pluginFormFactory
->createInstance($workflow_type, TransitionInterface::PLUGIN_FORM_KEY)
->validateConfigurationForm($form['type_settings'], $subform_state);
}
}