Search code examples
drupalimagefield

getting all ImageFields associated with a node


How do i get all the image fields attached to a content type on a full node without knowing the field names? Just out of curiosity, is there a way we can get all the fields of a specific type?

I am developing a module that needs image fields tied to a specific node and i'm using hook_node_view for fetching the node data.

I already viewed following post and it seems pretty relevant but i had difficulty understanding.

How to get the first image field from a node without knowing the field's name?


Solution

  • Well, i finally found the function i was looking for and it was pretty simple. All i had to do was to get all the fields field_info_instances() with $entity_type as the first parameter and then iterating over the result to get the widget type 'image_image' for ImageFields.