I have created field collection and added it to my content type. I have created a node, and now user can add field collections on this node. But i need to write into a file(some stuff) when user added new field collection or updated it. I need something like hook_node_insert and hook_node_update, i cant find anything for field collection.

In preprocess_node i have outputed field_collection_field and its returns only ids, and i can get them only by this code:

 $field_ids = array();
            //context_node = my current node,
            //field_block_id == field collection field
            foreach ($context_node->field_block_id['und'] as $element) {
                $field_ids[] = $element['value'];
 $field_collection = entity_load('field_collection_item', $field_ids);
  • Did you dpm($node); your hook_node_insert ? Commented Jan 31, 2013 at 16:22

2 Answers 2


A Field Collection Item is an entity, so the equivalents of the node hooks are hook_entity_insert()

Act on entities when inserted.

And hook_entity_update()

Act on entities when updated.

  • this is what i am looking for Commented Jan 31, 2013 at 16:43

the field collection APIs are defined in the field_collection.api.php

The hook function that would interest you is hook_field_collection_item_presave()

 * Acts on a field collection item being inserted or updated.
 * This hook is invoked before the field collection item is saved to the database.
 * @param FieldCollectionItemEntity $field_collection_item
 *   The field collection item that is being inserted or updated.
 * @see hook_entity_presave()
function hook_field_collection_item_presave(FieldCollectionItemEntity $field_collection_item) {
  $field_collection_item->name = 'foo';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.