1

I have multiple values in an entity reference field. I want to delete one of those values, but ::clear doesn't seem to work. I basically just want to do an unset, like:

$wrapper->field_entityrefs[3]->delete();

or something clean like that. What is the best way?

3
  • 1
    Not tried it, but how about just unset($wrapper->field_entityrefs[3])? – Clive Mar 17 '14 at 11:46
  • 1
    I've confirmed the unset($wrapper->field_entityrefs[3]) approach works, just follow it with a $wrapper->save() call. – tyler.frankenstein Jan 27 '15 at 16:14
  • tyler.frankenstein 's solution worked perfectly – Capy Aug 11 '16 at 17:40
0

This seems to work:

$wrapper->field_entityrefs[3]->set();

Also, to test if the field is there in the first place:

$wrapper->__isset('field_entityrefs');

I'm now finding myself calling __isset() on all wrapper fields.

1
  • I get warnings, such as Missing argument 1 for EntityDrupalWrapper::set() – AlxVallejo Feb 23 '15 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.