Enables custom select options and accompanying display widgets for CCK text fields. Preset Widget Options gives developers a lot of control over the handling and display of fields without having to declare a whole new field type.

This module should be installed only if another module requires it.

Modules using Preset Widget Options include: Creative Commons Widget.

Setup

Preset Widget Options provides two new options for field management and display.

  1. On the CCK field settings page for text fields, the "PHP code" collapsible fieldset, where site admins may enter custom PHP from which to draw options for selects or radios, is retitled "Advanced options" and given an additional setting, "Options handler". Here any custom options lists defined using Preset Widgets Options are made available.
  2. On the CCK field display settings form, each option handler is available as a display option for text fields.

Developer usage

Use Preset Widget Options to provide customized select options and display for a text field. This sample module implements hook_widget_options() to convert a regular text field into a select with options drawn from a preset list of countries and display consisting of a flag image with a link to a site with more information about the given country.

<?php
/**
* Implementation of hook_widget_options().
*/
function country_widget_preset_widget_options() {
 
$path = drupal_get_path('module', 'country_widget') . '/image';
  return array(
   
// Declare one or more types. Here we declare one, 'country'.
   
'country' => array(
     
'#title' => t('Country'),
     
// Options to be presented in a select.
     
'#options' => array(
       
'ca' => array(
         
// #title is required, any other properties are custom.
         
'#title' => t('Canada'),
         
'#image' => $path . '/ca.png',
         
'#link' => 'http://example.com/countries/ca',
        );
       
'us' => array(
         
'#title' => t('United States'),
         
'#image' => $path . '/us.png',
         
'#link' => 'http://example.com/countries/us',
        );
      ),
    ),
  );
}
/**
* Theme the output of a country field.
*
* A theme function named in the convention theme_{module_name}_{type}_field_value
* will override the standard display of a field.
*/
function theme_country_widget_country_field_value($option) {
 
$image = theme('image', $option['#image'], $option['#title'], $option['#title']);
  return
l($image, $option['#link'], array(), NULL, NULL, TRUE, TRUE);
}
?>

This module is partially supported by CivicActions.

Project Information

Downloads