Entity validator does not work with IEF

Created on 27 November 2022, almost 2 years ago
Updated 13 October 2023, about 1 year ago

Problem/Motivation

I have created an ConstraintValidator for my custom outer entity to check that not two of the referenced items have set the same date.

Steps to reproduce

* Create Validation plugin, attach it to outer entity in the entities annotation.

If I change a date in IEF and save the entity, I can see that in the validation plugin I still see the old values. Anyway after saving the referenced entities have the correct date.

Proposed resolution

I guess there is some problem with the order the entities are saved?

🐛 Bug report
Status

Active

Component

Code

Created by

🇩🇪Germany k4v

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇫🇮Finland aleksip Finland

    I came across this as well, and am able to reproduce it, and it does seem like a bug:

    1. Vanilla Drupal 10.1.x install with Inline Entity Form 1.0-rc15.
    2. Add field_articles entity reference field to page.
    3. Add a constraint validator checking that field_tags is not empty in referenced articles.
    4. Verify that validator works with core widget.
    5. Set simple IEF widget and remove an existing tag in the inline form, validator does not work on save.
    6. Add core patch from https://www.drupal.org/project/drupal/issues/2826717 🐛 EntityReferenceFieldItemList::referencedEntities might not return up-to-date entity objects Needs work .
    7. Now simple IEF widget works.
    8. Change to compex IEF widget, does not work with or without the core patch.

    Other possibly related IEF issues:

  • 🇫🇮Finland aleksip Finland

    After some more testing it seems that the constraint validator does work with the complex IEF widget if the core patch is applied and the IEF widget's Update button is clicked before saving the parent form.

    If the parent form is saved with an opened and modified complex IEF form, the validator does not get an entity with the modified values. But since modifications to the referenced entity are saved even without clicking Update, this seems to be a bug in the complex widget.

    Something that is probably good to mention here as well is that the core bug is replicated in Entity Reference Revisions, so if that module is used for the reference field a similar patch should be used from https://www.drupal.org/project/entity_reference_revisions/issues/3098924 🐛 referencedEntities() causes data loss Needs review .

Production build 0.71.5 2024