Problem/Motivation

Currently, the paragraph entity is built and validated in \Drupal\paragraphs\Plugin\Field\FieldWidget\ParagraphsWidget::elementValidate() but certain changes only happen after that in massageFormValues(), specifically the behavior settings as well as some language shuffling.

That means it is not possible to write validation constraints based on the behaviors

Proposed resolution

Move the validate call down into massageFormValues(), right before the needsSave(TRUE) call.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir created an issue. See original summary.

Berdir’s picture

Status: Active » Needs review
FileSize
1.05 KB

Lets see if anything complains about this.

Status: Needs review » Needs work

The last submitted patch, 2: paragraphs-validate-2935186-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Berdir’s picture

That patch passed the wrong form part to the validate function, this should be better.

Also added support to show validation errors on the correct behavior settings form element.

Berdir’s picture

Status: Needs work » Needs review
miro_dietiker’s picture

+++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
@@ -1913,7 +1914,6 @@ class ParagraphsWidget extends WidgetBase {
         // Validate all enabled behavior plugins.

If we are moving the validation of these elements away from elementValidate into massageFormValues, why can the Behavior validation still stay here?

  • miro_dietiker committed 1926c58 on 8.x-1.x authored by Berdir
    Issue #2935186 by Berdir: Move paragraph validation to massageFormValues...
miro_dietiker’s picture

Status: Needs review » Fixed
Related issues: +#2935571: Investigate double call to extractFormValues and recursion

Discussed, looks good...

But yeah, we should once look better why we need these elementValidate and massageFormValues as both then do extractFormValues.. See issue i created.

Thus, committed, thx! :-)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.