Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
pebosi CreditAttribution: pebosi commentedAnother use case is when adding a new "section"...
Comment #2
pebosi CreditAttribution: pebosi commentedAnyone?
Comment #3
pramodganore CreditAttribution: pramodganore commentedField 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();
}