New to Drupal and I'm assuming the answer is simple, I've looked through the test suites etc. and still missing the point it seems.
I have a node with a field collection (field_theatre_date_set) that will store a number of dates and times. I have loaded the node and the collection is there but it's empty.
I have used various forms of this and an obvious problem is that the $field_collection_item_value below array structure just isn't there.
Any further pointers greatly received.
$loop=0;
foreach($showing_array as $key=>$value){
$date='xxxx';
$time='xxxx';
$field_collection_item_value = $node->field_theatre_date_set[LANGUAGE_NONE][0]['value'];
$field_collection_item = entity_load('field_collection_item', array($field_collection_item_value)); // Load that field collection item
$field_collection_item->field_theatre_date_set_date[$node->language][$loop]['value'] = $date;
$field_collection_item->field_theatre_date_set_time[$node->language][$loop]['value'] = $time;
$loop++
}
$field_collection_item->save();
/**Update***/
Progress has been made. I still have an empty field_collection reference that needs to store a date and time.
I now understand that field collections store a value and a revision_id. I now need to work out how to store these revisions. I have the following code:
$field_collection_item = entity_create('field_collection_item', array('field_name' => 'field_theatre_date_set'));
$field_collection_item->setHostEntity('node', $node);
$field_collection_item->date[LANGUAGE_NONE][]['date'] = $date;
$field_collection_item->field_description[LANGUAGE_NONE][]['time'] = $time;
$field_collection_item->save();
Now when I output the field_collection_item I see the following where I am expecting to see the the value and revision:
[field_theatre_date_set] => Array
(
[und] => Array
(
[0] => Array
(
[entity] => FieldCollectionItemEntity Object
*RECURSION*
)
)
)
And at the very bottom of the array I have the dates and times wallowing on their own:
[date] => Array
(
[und] => Array
(
[0] => Array
(
[date] => 2014-03-13
)
)
)
[time] => Array
(
[und] => Array
(
[0] => Array
(
[time] => 19:45:00
)
)
)
Any pointers on how to move them into my field_theatre_date_set if they aren't expecting date and time values?
Thanks all for looking!