By JoshOrndorff on
I'm working on porting a module to Drupal 7, and I need to be sure that there is at least one field of type 'image' on a content type. The fields I'm looking for are the d7 equivalent of what used to be CCK imagefields. In d6 the module called filefield_get_field_list. But I can't find an equivalent to that in d7. Any ideas would really be helpful. Thanks a lot.
-Josh
Comments
In drupal 7, the Image field
In drupal 7, the Image field is now in core. You can even use the Field UI to manage your content types : http://drupal.org/handbook/modules/field-ui. There is a new level of content abstraction with entities, bundles and fields wich is really more powerful than CCK : http://drupal.org/node/707832.
Hope it will help you.
File Widget
Thanks a lot. That document brought me a long way both in solving this specific issue and getting a better conceptual understanding of the differences between fields and instances. For anyone else who is interested, I ended up using field_info_fields().
That being said, I have another question. I'm defining a new widget for fields of type 'file'. I have the widget defined and appearing, and I've even added some settings with hook_field_widget_settings_form(). But what I really need to do now is limit the available file extensions. In particular I want to only allow .pdf files to be uploaded. I see that the file.module implements its default extension values using hook_field_instance_settings_form() and my current code looks like this:
I've also tried:
And I've even tried outrageous things that obviously won't work like:
But nothing I've done will override the default file extensions of 'txt'.
Thanks again for any help!
-Josh
field_info_instances() also good
For anyone who comes across this after searching for something like 'drupal 7 get fields for node type' in google, I also found the function field_info_instances() quite useful. It provides you with instance information about the field pertaining to the particular content type (e.g. Label). The function field_info_fields() returns all fields and only provides element specific information not related to any particular content type.
Thanks!
that's exactly how I got there :)
To get a list of all the node fields:
where $source_node_type is the type of the node (not its name).