I have a node with a field type field_collection which has 2 items:
$node->field_field_collection['und'] = array(
0 => array('value' => 1),
1 => array('value' => 2),
);
on the save node drupal fire hook_node_presave:
/**
* Implementation of hook_node_presave.
*/
function mymodule_node_presave($node) {
$ewrapper = entity_metadata_wrapper('node', $node);
$wrapper_counter = 0;
$node_counter = 0;
foreach ($ewrapper->field_field_collection->getIterator() as $delta => $fc_wrapper) {
$wrapper_counter++;
}
foreach ($node->field_field_collection['und'] as $key => $value) {
$node_counter++;
}
}
after runing code
$wrapper_counter = 0;
$node_counter = 2;
what am I doing wrong?
I want to walk the field collection using entity_metadata_wrapper.
Drupal: 7.34
Entity API: 7.x-1.5
Field collection: 7.x-1.0-beta8
EntityListWrapper
is iterrable, why the need for->getIterator()
?getIterator()