0

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?

Community
  • 1
  • 1
xmaestro
  • 1,084
  • 2
  • 16
  • 44

2 Answers2

1

This can be done by checking all the fields of your content type & check its "type" field

if the type field is a image you can render it

Amey Mudras
  • 185
  • 5
0

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.

xmaestro
  • 1,084
  • 2
  • 16
  • 44