Closed (fixed)
Project:
Field collection
Version:
7.x-1.x-dev
Component:
Documentation
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
8 May 2013 at 18:00 UTC
Updated:
22 May 2013 at 19:00 UTC
What am I doing wrong here? This code works when I'm updating things like the node title, but not working when I update a field within a collection.
Background, 1 collection named otu_password with 3 fields, (1 field named otu_name (text) within that collection that I'm trying to update with php). The updated value is not saving. When I go to the node edit form the old value is still displayed. Any ideas?
//Load Node
$updateNode = node_load($nid);
//Setup Wrapper
$wrapper = entity_metadata_wrapper('node', $updateNode);
//Output Current Value (Works)
dsm($wrapper->field_otu_password[0]->field_otu_name->value());
//Chnage Value (Tried Both ways)
$wrapper->field_otu_password[0]->field_otu_name = 'New Value';
/*$wrapper->field_otu_password[0]->field_otu_name->set('New Value');*/
//Save New Value
$wrapper->save();
//Output New Value (Works)
dsm($wrapper->field_otu_password[0]->field_otu_name->value());
//Save Updated Node
node_save($updateNode);
Comments
Comment #1
timefor commentedSolved - I found this article,
http://rajanmayekar.com/blog/programmatically-creating-deleting-modifyin...
It didn't work exactly as expected but it lead me to working code. Looks like entity_load returns an array of objects instead of the object itself now.
I messed with this too long, hope this helps someone.
Comment #2.0
(not verified) commentedadded more details.