Hi,

how is it possbile to re-compute all computed fields on other field collection items of one node when one field collection gets updated?
I have a node containing one field-collection, where this field-collection ("homes", multiple values) itself contains another field-collection ("sections", multiple values). When i update one "section" the others in all other "homes" should be update too.

Regards

Comments

pebosi’s picture

Another use case is when adding a new "section"...

pebosi’s picture

Anyone?

pramodganore’s picture

Field collection items have their own entity id.
Updating should not be an issue

//update :: load existing entity and update it
$title ="my new title"; // capture what you want to update

$fc_id[] = $item_id; // passing one item_id (item id is unique for every collection item)
$collection = entity_load('field_collection_item', $fc_id); // takes array

foreach($collection as $item) {
$cwrapper = entity_metadata_wrapper('field_collection_item', $item); //using wrapper to make life easier

// UPDATE YOUR VALUES HERE
if(isset($title)) {
$cwrapper->field_section_title->set($title); //field_section_title = my machine name for field
}
if(isset($body)) {
$cwrapper->field_section_body->set($body);
}
// save this individual entity (fc: section)
$cwrapper->save();
}