Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / workflows / src / Form / WorkflowStateAddForm.php
index 4b5f723395534174446cddc591100acba015f8fb..1abc8e3df734dffddbe463c8766f2be9ac9a4c71 100644 (file)
@@ -116,15 +116,13 @@ class WorkflowStateAddForm extends EntityForm {
    *   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']);
   }
 
   /**
@@ -162,7 +160,7 @@ class WorkflowStateAddForm extends EntityForm {
     }
 
     $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'));