Adding different fields

Last modified: November 10, 2009 - 12:59

The way to add any FAPI field is to use the drupal_alter 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.
*/

/**
* Callback for drupal_alter('imagefield_extended_widget').
*/
function MYMODULE_imagefield_extended_widget_alter($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.

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.

 
 

Drupal is a registered trademark of Dries Buytaert.