I'm trying to delete all values of a multivalued field containing a field collection. I want access with Entity API wrappers. I use this in a custom rule with hook_rules_action_info()

I'm using drupal 7.39 and field collection modules 7.x-1.0-beta8 and

I'm testing this code but doesn't work for me, this node has 2 values in field_collection

$node_wrapper = entity_metadata_wrapper('node', $node);
dpm($facWrapper->field_collection,"Field Collection");
//Prints a EntityListWrapper object
dpm($facWrapper->field_collection->count(),"Field Collection count");
//Prints zero, it should be 2
dpm($facWrapper->field_collection->value(),"Field Collection value");
//Prints array() 0 elements, it should be 2 elements
//And obviously doesn't enter into this foreach, it should enter
foreach ($facWrapper->field_collection as $fc) {
  dpm($fc,"Field collection item");

The questions are:

  • How to load or access to the field_collection in the entity wrapper way ?
  • When I have access, How can I delete ? I want to delete the field_collection_item and its reference in the node.

1 Answer 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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