Adding different fields

Last updated on
30 April 2025

The way to add any FAPI field is to use the imagefield_extended_widget hook. All you need is a custom module with this function and an info file. Remember to replace the MYMODULE with a relevant module name.

; MYMODULE.info
name = MYMODULE
description = "Adds a select element to all imagefield_extended widgets"
package = CCK
core = 6.x
dependencies[] = imagefield_extended

<?php
/**
 * @file
 * MYMODULE.module
 * Adds fields for imagefield_extended widgets.
 */

/**
 * Implementation of hook_imagefield_extended_widget().
 */
function MYMODULE_imagefield_extended_widget($element, $extra_values) {
  // If you need the field or widget to conditionally add a FAPI field, use these.
  $field = content_fields($element['#field_name'], $element['#type_name']);
  $widget = $field['widget'];

  return array(
    'MYFIELD' => array(
      '#type' => 'select',
      '#title' => t('My select field'),
      '#options' => array(
         'a' => t('A option'),
         'b' => t('B option'),
      ),
      // this makes b the default value when the value is not set.
      '#default_value' => isset($extra_values['MYFIELD']) ? $extra_values['MYFIELD'] : 'b',
    ),
  );
}

?>

The data should be saved and loaded by FileField and your theming functions would present the value to the end user.

To use your custom field within Views you need to let FileField know about it:

function MYMODULE_filefield_data_info() {     
  return array(
    'MYFIELD' => array(
      'title' => t('My select field')
    ),
  );
}

This would display the value only ("a", "b" etc.), not the option text ("A option", "B option").

The module is by design, a helper tool for developers, with a few extra "ease of use" fields to cover 80% use cases. The direction of this module will never follow Webform by having addition "widgets" added.

Help improve this page

Page status: Not set

You can: