When the entityreference field is placed on an entity that does not have bundles (eg the 'user' entity) the following notice is thrown when the field is validated:

Notice: Undefined property: stdClass::$type in EntityReferenceFieldBehaviorUnique->validate() (line 15 of /sites/all/modules/contrib/entityreference_unique/plugins/behavior/EntityReferenceFieldBehaviorUnique.class.php

Comments

pfrenssen’s picture

Status: Active » Needs review
StatusFileSize
new1.06 KB
manuelBS’s picture

Status: Needs review » Needs work

Thanks for pointing this out. But I think we should better use the API to figure out the bundle, just as

$info = entity_get_info($entity_type);
if (empty($info['entity keys']['bundle'])) {
return $entity_type;
} else {
return $entity->{$info['entity keys']['bundle']};
}

What do you think? If you want, please update the patch and I will commit it.

pfrenssen’s picture

Status: Needs work » Needs review
StatusFileSize
new1.17 KB

Sure! Here's an updated patch.

spadxiii’s picture

The method is already passed an $instance of the field. Why retrieve it manually?

tessa bakker’s picture

Status: Needs review » Closed (duplicate)

Tested SpadXIII's comment with success.

#2557039: Add i18n support for translation of labels will address this issue also with i18n support.