Problem/Motivation
Right now, in order to save the values a user has entered, we overriding EntityForm::copyFormValuesToEntity
in all of these forms:
WorkflowStateEditForm
WorkflowStateAddForm
WorkflowTransitionAddForm
WorkflowTransitionEditForm
Since the workflows is strict about the validity of the states and transitions it will add to a workflow, if you enter an invalid machine name for example, an exception is triggered which bubbles up to the user.
In #2842193: Exception in Workflow::addState when an invalid machine name is given we fixed this by reimplementing the validation provided by the machine_name element and the validateForm
method in order to prevent this from happening:
class WorkflowStateAddForm {
...
protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
// 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']);
}
}
It seems this was only done for states however, because the transition forms had already solved this another way:
protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
if (!$form_state->isValidationComplete()) {
// Only do something once form validation is complete.
return;
}
Proposed resolution
For consistency, lets use the same strategy everywhere and at the same time make things more DRY by not reimplementing validation rules.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#2 | 2899248-2.patch | 3.14 KB | Sam152 |
Comments
Comment #2
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #3
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #4
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #6
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedBumping for a review. Would be nice to get this clean-up in.
Comment #7
borisson_This makes sense and it passes all tests. I couldn't find any other places where the duplication had happened.
Comment #8
larowlantest failed?
Comment #9
borisson_That was the failure on the previous run, it's green again, setting to RTBC.
Comment #10
alexpottCommitted 5a6f295 and pushed to 8.6.x. Thanks!