Understanding Field Collection Values
Last updated on
30 April 2025
When a field collection is added to a user, node, or other Drupal entity it is represented with a field type of field_collection_item. The value stored in the field_collection_item field is the id of the field collection, not the individual values of the fields making up the field_collection_item.
For example, take the following configuration:
- Node type Playlist
- Playlist has a field collection named Track (field_track)
field_track of type field collection - Track field collection consists of the fields Song and Artist
field_song of type text
field_artist of type text
A Playlist node is created with two tracks. For the purposes of the example the following values are assigned:
- Playlist node id: 25
- 1st track: field_collection id: 17
field_song: The Drupal Song
field_artist: Lullabots - 2nd track: field_collection id: 18
field_song: Drupal Heaven (I Shall Be Released)
field_artist: The Secret Kitten Killers
When node 25 is loaded, field_track has the following value:
[field_track] => Array
(
[und] => Array
(
[0] => Array
(
[value] => 17
)
[1] => Array
(
[value] => 18
)
)
)To get the values of the individual field items call the entity_load function:
$node25 = node_load(25);
$track_1 = entity_load('field_collection_item', array($node25->field_track[LANGUAGE_NONE][0]['value']));
$track_2 = entity_load('field_collection_item', array($node25->field_track[LANGUAGE_NONE][1]['value']));
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion