Closed (fixed)
Project:
Field collection
Version:
7.x-1.x-dev
Component:
Documentation
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
4 Jan 2012 at 09:45 UTC
Updated:
20 Jan 2012 at 23:30 UTC
Could someone please provide an example on how to create the fields and add values?
Example: Map (node) has unlimited areas (field collection field). Each area has unlimited layers (field collection field). The area fc. have normal fields and the layer fc. The layer fc. only have normal fields.
Creating and attaching an fc. to a node is fine, but I can't work out how to add another fc. to that fc..
I assume the 2nd fc. should use the 1st fc. id as HostEntity?!
Any ideas, suggestions are welcome. Thanks a lot.
Comments
Comment #1
Greg Varga commentedSo it turned out that the solution was very simple:
1) Create the base node (Map) and save it using node_save() -> $map_node
2) Create the first field collection (Area)
The Area fc. contains another fc. called Layers, but for now, we can ignore that. Add the required values, set the HostEntity, which is the $map_node and save the fc.
3) Create the second field collection (Layers)
This is pretty much the same as the previous code, but the HostEntity is pointing to the Area fc. and the HostEntity type is "field_collection_item"
Once everything is saved, you are good to go. Good luck.
Comment #2
Greg Varga commented