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?

有帮助吗?

解决方案 2

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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top