Last updated January 31, 2012. Created by Alan D. on November 10, 2009.
Edited by imclean. Log in to edit this page.
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.
*/
/**
* 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:
<?php
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.
Comments
Taxonomy Field
How to add taxonomy field to this imagefield_extended widget ? Is it possible ?
Not easily, but you can use
Not easily, but you can use the alter form example above to manually add a taxonomic select list.
Alan Davison
Back roads somewhere in South America
Views integration
To use your custom field in Views you can let FileField know about it:
<?phpfunction 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").