* The current state of the form.
*/
protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
+ if (!$form_state->isValidationComplete()) {
+ // Only do something once form validation is complete.
+ return;
+ }
/** @var \Drupal\workflows\WorkflowInterface $entity */
$values = $form_state->getValues();
- $type_plugin = $entity->getTypePlugin();
-
- // Replicate the validation that Workflow::addState() does internally as the
- // form values have not been validated at this point.
- if (!$type_plugin->hasState($values['id']) && !preg_match('/[^a-z0-9_]+/', $values['id'])) {
- $type_plugin->addState($values['id'], $values['label']);
- }
+ $entity->getTypePlugin()->addState($values['id'], $values['label']);
}
/**
}
$workflow->save();
- drupal_set_message($this->t('Created %label state.', [
+ $this->messenger()->addStatus($this->t('Created %label state.', [
'%label' => $workflow->getTypePlugin()->getState($form_state->getValue('id'))->label(),
]));
$form_state->setRedirectUrl($workflow->toUrl('edit-form'));