+ $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']);
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function validateForm(array &$form, FormStateInterface $form_state) {
+ parent::validateForm($form, $form_state);
+ /** @var \Drupal\workflows\WorkflowTypeInterface $workflow_type */
+ $workflow = $this->entity;
+ $workflow_type = $workflow->getTypePlugin();