Scenario:
- Create a ER field "field_foo", target type node, bundle type "foo"
- Create a new node
- Type in a value "bar (123)" where 123 is nid for node with type "bar" into "field_foo"

Expected behavior:
- ER should validate against target bundle settings, and throw an error

Observed behavior:
- ER allows value to be saved without any validation against bundle

Comments

aaronbauman’s picture

Status: Active » Needs review
StatusFileSize
new5.65 KB

OK, this ended up touching a bunch of different pieces, including a related bug in entityreference_field_validate().
Fortunately the patch is relatively straightforward, and includes tests.

In this patch:

  • Update entityreference_field_validate() to actually perform validation when no valid references are given. (Previously validation was ignored if there was only one invalid reference).
  • Update EntityReference_SelectionHandler_Generic::validateReferencableEntities() to filter by target bundle settings if applicable.
  • Add a test for target bundle settings.
  • Update EntityReferenceHandlersTestCase::assertReferencable() to properly count multi-bundle arguments / target bundle settings.

Status: Needs review » Needs work

The last submitted patch, 1: entityreference-bundle_settings_validation-2516716-1.patch, failed testing.

aaronbauman’s picture

Status: Needs work » Needs review
StatusFileSize
new6.39 KB

Slightly updated test

rooby’s picture

Status: Needs review » Reviewed & tested by the community

This fixes the issue of validation being skipped if there are no valid results returned from the view.

rooby’s picture

Priority: Normal » Major

This is arguably major since there is incorrect validation happening, which can cause data corruption.

spotzero’s picture

Status: Reviewed & tested by the community » Needs work

The fix works, but the new tests pass with or without the code fixes. So the tests don't actually appear to test this issue.

drumm’s picture

Issue tags: +affects drupal.org

We have this issue present here on the issue page, the related & parent issue fields.