1

I have a nodetype which is has a connected field collection (multiple values). In this case one of items of the collection is a date and I have got the ID of this one. So:

field_collection_item_load($did);

takes me just half the way home, since I still need some data of the node, hosting this collection, which in turn holds that item.

Illustration:

node // need that id
  + dates (Field Collection)
     + item (of item of the field collection)
       + ....
       + date // got this id
       + more fields
     + ...
     + more items

Any Ideas?

1 Answer 1

3

you may want to try hostEntity() method (link)

Returns the host entity, which embeds this field collection item.

Then you'll be able to extract nid from the result returned by hostEntity().

but it is not clear what are you loading with field_collection_item_load($did);

is $did the id of the field_collection item - meaning the field collection and not the field in it? if so, than you can do something like this

$entity = entity_load_single('field_collection_item', $did);
$host_entity = $entity->hostEntity();
$nid = $host_entity->nid;  // returns node id of the node that hosts given field collection
1
  • Thank you! That's it! $did does in this case refer to "dateID", which is the itemID in this case.
    – philipp
    Feb 4, 2016 at 7:08

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.