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

greg_gy’s picture

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.

JoshOrndorff’s picture

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:

<?php
function pdf_to_imagefield_field_instance_settings_form($widget, $instance) {
  // set & lock pdf extension from modification in the current instance
  $instance['settings']['file_extensions']['#default_value'] = 'pdf';
  $instance['settings']['file_extensions']['#disabled'] = TRUE;

  // get standard settings from file module passing it our modified instance
  $form = module_invoke('file', 'field_instance_settings_form', $widget, $instance);

  return $form;
}
?>

I've also tried:

<?php
function pdf_to_imagefield_field_instance_settings_form($widget, $instance) {

  // get standard settings from file module
  $form = module_invoke('file', 'field_instance_settings_form', $widget, $instance);

  // set & lock pdf extension from modification in the current instance
  $form['file_extensions']['#default_value'] = 'pdf';
  $form['settings']['file_extensions']['#disabled'] = TRUE;

  return $form;
}
?>

And I've even tried outrageous things that obviously won't work like:

<?php
function pdf_to_imagefield_field_instance_settings_form($widget, $instance) {

  return array();
}
?>

But nothing I've done will override the default file extensions of 'txt'.

Thanks again for any help!
-Josh

drclaw’s picture

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.

mreynov@gmail.com’s picture

that's exactly how I got there :)

talreg’s picture

$data=field_info_instances("node",$source_node_type);

where $source_node_type is the type of the node (not its name).