If you use a debugger to watch entityreference_field_validate(...) function, you'll see that the IEF fields pass right through this section:


foreach ($items as $delta => $item) {
if (!entityreference_field_is_empty($item, $field) && $item['target_id'] !== NULL) {
$ids[$item['target_id']] = $delta;
}
}

There is no $item['target_id'], so the $valid_ids is never checked.

I'm not sure if this is a feature or a bug. I ran into it when using EFQ Views as my autocomplete results which does set a a target_id, but it's directly on $item, $item is not an array like $item['target_id'] = 1234, but $item = 1234. That was causing invalid referenced entity errors.

IEF will create an $item like this:

$item = array(
'entities' => array(
array(
'delta' => 0,
'actions' => array(...)
)
)
);

The entityreference_field_validate(...) function expects $item to have a 'target_id' key for it to actually validate the $ids.

CommentFileSizeAuthor
#1 entity-selection.png13.36 KBbendiy
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bendiy’s picture

FileSize
13.36 KB
bojanz’s picture

We have a bugfix for a similar issue in #1659586: Support Taxonomy term reference fields, basically an #element_validate callback that sets the id to NULL.
We probably need to make that fix work for all field types, and commit it.