1

Where can I see the options accepted by the field API for the widget type?

$instance = array(
  'field_name' => $field_name,
  'label' => 'Demofield Demo',
  'description' => 'This is a demonstration text field.'
  'widget' => array(
      'type' => 'text_textfield',
  )
);

2 Answers 2

1

The default options for each widget are listed in the hook_field_widget_info() implementation.

You can find all such implementations in core by searching for "_field_widget_info": You can find a list of all core implementations of that hook by searching for "_field_widget_info": http://api.drupal.org/api/search/7/_field_widget_info

2

There isn't a preset list of widget types; the widget types are the ones defined from modules that implement fields. Using the following code, you can get the list of all the widget types implemented by the enabled modules:

$array = module_invoke_all('field_info');

foreach ($array as $id => $info) {
  print $info['default_widget'];
}

The code essentially invokes all the implementations of hook_field_info(), and print what is defined as default widget.
If you have installed Devel, instead of print you can use dsm().

If you want to know the settings available for the field implementation, then you need to look for the implementation of hook_field_settings_form(), such as list_field_settings_form(), or text_field_settings_form().

function text_field_settings_form($field, $instance, $has_data) {
  $settings = $field['settings'];

  $form = array();

  if ($field['type'] == 'text') {
    $form['max_length'] = array(
      '#type' => 'textfield', 
      '#title' => t('Maximum length'), 
      '#default_value' => $settings['max_length'], 
      '#required' => TRUE, 
      '#description' => t('The maximum length of the field in characters.'), 
      '#element_validate' => array('_element_validate_integer_positive'),
      // @todo: If $has_data, add a validate handler that only allows
      // max_length to increase. 
      '#disabled' => $has_data,
    );
  }

  return $form;
}
2
  • You can also look at the source code of the widget select in the field UI, which contains all possible values.
    – Berdir
    Commented Jun 6, 2011 at 15:45
  • thx for response. But as much as I see the options for each one? e.g. the number of lines in textareas? Commented Jun 6, 2011 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.