I have a problem with Paragraphs EXPERIMENTAL validation.

How to reproduce

  1. Create paragraph type with entity reference field, which allows to reference articles
  2. In content type Page create entity reference revisions field with Type of item to reference: Paragraphs
  3. In content type Page go to Manage form display and setup field widget as on screen: Paragraph form display setup
  4. Create article
  5. Create page with reference to article inside paragraph
  6. Delete/unpublish article. Can be via e.g. drush drush ev 'Drupal::entityTypeManager()->getStorage("node")->load(<ARTICLE_ENTITY_ID>)->delete()';
  7. Edit page and try to save. Error message will be displayed: Closed paragraph validation message

Problems

Not user friendly validation message, when paragraph is closed

When paragraph is closed, after submit I see message:

Validation error on collapsed paragraph field_references.0.target_id: The referenced entity (node: ) does not exist.

The problem is, that field_references.0.target_id tells me a lot, but for users is useless.

Potential solution

It will be good to replace that part of message with field labels. Like Parent field label >> Paragraph field label. Or if it is too hard, remove that part of message. But this will be useful only is second problem will be solved (Paragraph remains collapsed, when validation fails).

Paragraph remains collapsed, when validation fails

Paragraph stays collapsed, when validation error occurs inside. It is hard to determine for the user, where exactly the problem occurs (for users).

Potential solution

Make paragraphs with validation errors expanded. But I saw this comment in code:

Assume that the entity is being saved/previewed, in this case,
validate even the closed paragraphs. If there are validation errors,
add them on the parent level. Validation errors do not rebuild the
form so it's not possible to auto-uncollapse the form at this point.

And I wonder, how hard it will be to expand on validation failure.

Issue fork paragraphs-3095945

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gugalamaciek created an issue. See original summary.

gugalamaciek’s picture

Issue summary: View changes
gugalamaciek’s picture

Issue summary: View changes
gugalamaciek’s picture

Issue summary: View changes
gugalamaciek’s picture

Issue summary: View changes
gugalamaciek’s picture

Issue summary: View changes
gugalamaciek’s picture

In patch, there is our improvement of error message, which is displayed when paragraph is closed. Our analyze shows us, that expanding paragraph will be hard thing to achieve. We decided to just improve error message to be more user friendly by now. Format of the message:

@message (@field_name » @paragraph_label [@delta] » @nested_field_name [@nested_delta])

gugalamaciek’s picture

Small bug fix.

Berdir’s picture

Status: Active » Needs review
Issue tags: -paragraph experimental

Don't forget to set issues to needs review when you upload patches so that the test are run.

Berdir’s picture

Status: Needs review » Needs work

The tests need to be updated for the changed message.

mallezie made their first commit to this issue’s fork.

mallezie’s picture

This patch causes an issue when a non-field-level constraint is hit.

In our case we hit the EntityWorkspaceConflictConstraint.
Not sure how to concretely reproduce, but in our situation we have nodes with nested paragraphs. When we create nodes in the non-default workspace and deploy those to Live we can end up in a situation where our nested paragraph links to the paragraph revision which is in the non-default workspace.
When saving we hit an error in the Paragraphswidget when adding the validation message.

'@nested_field_name' => $paragraphs_entity->getFieldDefinition($property_data[0])->getLabel(),

This is caused because the EntityWorkspaceConflictConstraint property_data is an empty string, so the getFieldDefinition returns NULL, causing the getLabel on it to fail.
Proposed resolution

For now i added a check for the property_data to adjust the message instead of failing. This keeps the validation error, but doesn't cause the fatal error.

mallezie’s picture

Status: Needs work » Needs review

Made the changes in the new merge request flow.
To check the patch check https://git.drupalcode.org/issue/paragraphs-3095945/-/commit/c62920e6010...

thomaswalther’s picture

I have Reference fields in a Taxonomy.
Before updating to 8.x-1.12 i have no problems.
After update to 8.x-1.12 I get this error:

Validation error on collapsed paragraph field_view_viewref.0.target_id: Die referenzierte Entität (view: manufacturer) existiert nicht.

After patch fix #8 or #14 the error still occurs, but now with this message:

GERMAN: Die referenzierte Entität (view: manufacturer) existiert nicht. (Absätze » Automatisch generierte Ansicht [3] » View [1])
DEEPL: The referenced entity (view: manufacturer) does not exist. (Paragraphs Â" Automatically generated view [3] Â" View [1])

isholgueras’s picture

I came to this issue because I have the same issue after updating to 8.x-1.12, as @thomaswalther said as well.

Maybe this is a silly question, but shouldn't be better to delete the paragraph references of the entity deleted? Is there any difficulty of doing this?

I know it's not just the entity_id itself, you need to know if it's a node, user, term,... but for me, imho, souldn't we just delete these orphaned references when deleting the entity?

Maybe I'm missing the context or something.

nessthehero’s picture

I'm also having a similar issue. We have a module that imports from a system and creates taxonomy terms in the CMS, and also deletes them if they are removed from the original system. However, if those taxonomy terms were selected in a collapsed Paragraph component, the page throws an error until the item is expanded and resaved.

Is there any way to clean up those references so that this error does not occur?

Alan Ridgway’s picture

Status: Needs review » Needs work

The last submitted patch, 18: 3095945-paragraphs-error_message.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

dwisnousky’s picture

Checking to see if A variable can be removed without issues

osopolar’s picture

Issue summary: View changes

Also happens while unpublishing the referenced (article) node. I also added this to the description step 6.

Having a page with many paragraphs it could be challenging for editors to find the right one. It would be nice if the error bubbles up and highlight the paragraph where the error happens.

lobodacyril’s picture

When I use #18 patch, I get weird and not informative message:

The referenced entity (node: 229) does not exist. (Paragraphs » Articles [4] » Articles [1])

Not sure what is the  symbol.

lobodacyril’s picture

Status: Needs work » Closed (duplicate)
Related issues: +#3027525: Show the paragraph and field label of fields that fail validation

I suppose https://www.drupal.org/project/paragraphs/issues/3027525 is the duplicate and it works better for me.