Last updated 16 March 2014. Created on 27 November 2011.
Edited by MatthijsG, dale42, wmostrey, pfrenssen. Log in to edit this page.


The Field Collection module is the successor to the CCK3 Multigroup. It allows a set of fields to be combined together and treated as a single field. For example, a field collection named Playlist can be created consisting of the text fields Song and Artist. When a Playlist entry is created the Song and Artist fields are presented together as elements of the Playlist field.


When the Field Collection module is installed a new Field type named 'field collection' becomes available in the Manage fields tab of supported entities. In a basic Drupal installation these are:

  • Content types
    e.g. Home > Administration > Structure > Content types > Basic page > Manage fields
  • People/Accounts
    Home > Administration > Configuration > People > Account settings > Manage fields
  • Taxonomy
    e.g. Home > Administration > Structure > Taxonomy > Tags > Manage fields

Manage or adding a field collections

After the field collection field is created it's managed under from Home > Administration > Structure > Field collections. This is where fields are added to the field collections created in the Manage fields tab.

There is one permission, Administer field collections. It allows the holder to create and delete fields on field collections.

Example Usage

Make sure both the Field Collection and Field UI modules are enabled to follow this tutorial.

You are creating music playlists, which consists of multiple songs. Each song has a specific song name and artist.

  • Go to admin/structure/types/add. Create a new content type: Playlist
  • Add a new field to it: Track
    • type: Field collection
    • widget: Embedded
    • number of values: Unlimited)
  • Go to admin/structure/field-collections and click on "Manage fields" for the created Track field
  • Add two fields to it: Song, Artist (type Text)

When you now add a new node of type "Playlist" you can add as many tracks to it as you like.

Looking for support? Visit the forums, or join #drupal-support in IRC.


Ahmad Kharbat’s picture

Node load doesn't seem to load the field collection of hosting node.. The previous examples show how to save values to a node, what about loading existing values?


charlie-s’s picture

The field_collection entity id(s) are available to you when using node_load via $node->field_collection_name. Once you've gotten the entity_id you can use entity_load('field_collection', $node->field_collection_name[LANGUAGE_NONE][0]['value']) to get the entire entity as an object. Something like this will get you all of the data:

foreach ($node->field_collection_name[LANGUAGE_NONE] as $entity_id) {
  $entity = entity_load('field_collection', $entity_id['value']);
mareks’s picture

this worked for me in D7

entity_load('field_collection_item', $coll_item_id);

// in my case the $coll_item_id comes from $node->MY_FIELD[LANGUAGE_NONE]['0']['value']
charlie-s’s picture

My bad, my original code should have been 'field_collection_item', not 'field_collection'.

girishmuraly’s picture

Also, as per the signature of entity_load(), the example code should be

foreach ($node->field_collection_name[LANGUAGE_NONE] as $entity_id) {
  $entity = entity_load('field_collection_items', array($entity_id['value']));
charlie-s’s picture

I believe entity_load('field_collection_items' should be entity_load('field_collection_item' without the "s".

girishmuraly’s picture

Correct :)

So finally:

foreach ($node->field_collection_name[LANGUAGE_NONE] as $entity_id) {
  $entity = entity_load('field_collection_item', array($entity_id['value']));
orgnsm’s picture

is there a way to obtain the values other than using entity_load or entityFieldQuery? i'm looking to use db_select or db_query for speed and flexibility...

mghatiya’s picture

Can there be some documentation on theming field collections? I don't know where to put field-collection-item.tpl.php and in what name. I found couple of threads talking about it, but information was not quite concrete, and when I do what is mentioned in them, it is not working.

Nehbur’s picture

The method of Mareks works, althought without identifiers for me. I used

  $test = entity_load('field_collection_item', $ids = FALSE);
  echo '<pre>';

$test now becomes an array with everything associated witht the field_collection_item. If you have more collection, they will all be in there. Now it's a matter of extracting what you need from it. Will update this comment if I know more.

Edit: this next bit gets a value from the collection, thanks to sijuwi who just posted a ticket to this thread!

  $field_collection = entity_load('field_collection_item', array($node->field_lima_variant_coll['und'][0]['value']));
  print $field_collection[1]->field_lima_variant_text['und'][0]['value']
hermes_costell’s picture

I tried to do some more advanced use of this module and as of 3/2012 it's not fun. Some things I could use help understanding:

What happens when a node is cloned?

// for instance...
$node = node_load($my_old_id);
$node->nid = NULL;
node_save($node); //cloning the old node

Do the field collection items pointing at the old node now point at BOTH nodes? Or are they cloned too?

And how to delete/remove field collection associations with a node? At the moment there's plenty of documentation about how to add field collections, and collect their data - what about deleting one or more field collection values from a node? Or changing them to point to a different field collection value, etc?

Thanks very much.

Drupal dev’s picture

I want to create a field collection to group two fields in a content type programmatically so that when the user installs the module, the module installs the content type and let the user create content through 'Add Content' option .

I have created two fields and field collection.I have created the field using field_create_field function in HOOK_install. I dont know how to link the field collection with the two fields in the code. I have searched over forum and I came across various materials just explaining how to add,edit and delete values of field collection programmactically but I could not find any useful information on how to create field collection in content type. Any help on this topic will be much appreciated.

In my code to create the content type with the field collection,the content type is created well with the field collection but when I check in the structures -> field Collection -> field_group->manage field, The fields are not getting displayed there and when I go to 'add content' the field collection does not have those fields but the fields are displayed outside the field collection container

shocknawe’s picture


I'm currently trying to use this with the 'View Datasource' to create a 2D array of objects in xml.

I'm not yet sure on how to do it properly, so i have to ask...
Is this possible?

shomari’s picture

Did you have any success using this module with View Datasource?

pmichelazzo’s picture

I'm thinking about the differences between field collection and content type in a scenario like this:

I have a recipe with different steps to do it. What's the best: use a field collection where I can put the image and description of the step or use a content type "Steps recipes" with the image and description fields inside and make a entity reference for the recipe content type?

I think that this scenario could be anyone, e.g. artists and their songs, malls with their stores, etc.

So, when we use a field collection or a content type?


mindxplorer’s picture

I would like to use the particular values of the fields grouped in a field collection for rewriting the output in a view. But I struggle to find the right token to achieve this. In the token list (under the rewrite field) only the whole fields collection is mentioned.
Is it possible to access the fields of a field collection directly?

BrendanSmith’s picture

Didn't see this mentioned anywhere, apologies if it has. For those who want to know, you can add new view modes for your field collections programmatically much like you would for nodes with a hook_entity_info_alter().

For Example

function MY_MODULE_entity_info_alter(&entity_info) {
$entity_info['field_collection_item']['view modes']['test'] = array(
    'label' => t('test'),
    'custom settings' => TRUE,
polaki_viswanath’s picture


I needed to to add / update field collections to node entities without updating the node entities. I tried two ways listed in and but none of them seems to be working exactly the way I want.

I tried as follows:

$node = node_load($nid);
$field_collection_item = entity_create('field_collection_item', array('field_name' => 'field_college_rating_data'));
$field_collection_item->setHostEntity('node', $node);
$field_collection_item->field_text1['und'][0]['tid'] = $form_state['input']['field_text1']['und'];
$field_collection_item->field_text2['und'][0]['value'] = $form_state['input']['field_text2']['und'];

It added a field collection but it updates the node.

I also tried to alter the field collection form submit and used custom submit handler as follows:

function own_custom_field_collection_submit($form,$form_state) {
  $field_collection_item = field_collection_item_form_submit_build_field_collection($form, $form_state);
  drupal_set_message(t('The changes have been saved.'));
  $form_state['redirect'] = $field_collection_item->path();

I have copied this code from core field collection module to change the default argument to "TRUE" in the save function. It added the field collection but didn't associated with the parent node.

I need to save the field collection separately since my node entity form is very large with 50 to 60 fields and field collections and I don't want to update it as many times as I add / update any field collections to the node.

Any help will be much appreciated. Thanks

dreamer777’s picture

Hi, I have the same problem. Did you manage to solve it?

Rob6566’s picture

Hey - I'm sure you've solved this already, but maybe this will help someone else.


$field_collection_item->save takes a parameter $skip_host_save, which defaults to false. Setting it to true prevents the parent node/field collection from being saved.

Alan D.’s picture

In case it helps someone :)

  $efq = new EntityFieldQuery();
  $efq->entityCondition('entity_type', 'field_collection_item');

  // No bundle value, use field name
  $efq->propertyCondition('field_name', 'field_appointment_document');

   // I'm restricting to search items attached to something, so filtering by the FC I want to check.
  $efq->propertyCondition('item_id', $doc_fc_ids);

  // We don't want revisions!
  $efq->propertyCondition('archived', 0);

  // An example to filter by a field attached to the FC.
  $efq->fieldCondition('field_document_type', 'tid', array(123,432));

  // No date information or useful other property info, but I want the newest one only.
  // So highest ID is the newest, and only return one result.
  $efq->propertyOrderBy('item_id', 'DESC');
  $efq->range(0, 1);

  // See if we have any results and load the field collection object.
  if (!empty($results['field_collection_item'])) {
    $field_collections = field_collection_item_load_multiple(array_keys($results['field_collection_item']));
    $field_collection = reset($field_collections);