summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2018-05-03 22:12:56 (GMT)
committerAlex Pott2018-05-03 22:12:56 (GMT)
commit5a6f295406c84a36bf815555c40bc8d13f78e81d (patch)
tree77624aa0b80fadbcf196c9cea234a3a3221955f6
parent7c6f4aec37eaf2c1f8c789666fda50485e0206aa (diff)
Issue #2899248 by Sam152: Don't reimplement validation rules for workflow state add/edit forms in ::copyFormValuesToEntity
-rw-r--r--core/modules/workflows/src/Form/WorkflowStateAddForm.php12
-rw-r--r--core/modules/workflows/src/Form/WorkflowStateEditForm.php4
-rw-r--r--core/modules/workflows/tests/src/Functional/WorkflowUiTest.php7
3 files changed, 16 insertions, 7 deletions
diff --git a/core/modules/workflows/src/Form/WorkflowStateAddForm.php b/core/modules/workflows/src/Form/WorkflowStateAddForm.php
index 5eb1b9a..1abc8e3 100644
--- a/core/modules/workflows/src/Form/WorkflowStateAddForm.php
+++ b/core/modules/workflows/src/Form/WorkflowStateAddForm.php
@@ -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']);
}
/**
diff --git a/core/modules/workflows/src/Form/WorkflowStateEditForm.php b/core/modules/workflows/src/Form/WorkflowStateEditForm.php
index 4fe5f5e..7b8b903 100644
--- a/core/modules/workflows/src/Form/WorkflowStateEditForm.php
+++ b/core/modules/workflows/src/Form/WorkflowStateEditForm.php
@@ -161,6 +161,10 @@ class WorkflowStateEditForm 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();
$entity->getTypePlugin()->setStateLabel($values['id'], $values['label']);
diff --git a/core/modules/workflows/tests/src/Functional/WorkflowUiTest.php b/core/modules/workflows/tests/src/Functional/WorkflowUiTest.php
index 487e28c..227ddd7 100644
--- a/core/modules/workflows/tests/src/Functional/WorkflowUiTest.php
+++ b/core/modules/workflows/tests/src/Functional/WorkflowUiTest.php
@@ -90,12 +90,19 @@ class WorkflowUiTest extends BrowserTestBase {
])->save();
$this->drupalLogin($this->createUser(['administer workflows']));
+
$this->drupalPostForm('admin/config/workflow/workflows/manage/test_workflow/add_state', [
'label' => 'Test State',
'id' => 'Invalid ID',
], 'Save');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
+
+ $this->drupalPostForm('admin/config/workflow/workflows/manage/test_workflow/add_transition', [
+ 'label' => 'Test Transition',
+ 'id' => 'Invalid ID',
+ ], 'Save');
+ $this->assertSession()->pageTextContains('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
}
/**