Contributions API

optionwidgets_form_alter

Definition

optionwidgets_form_alter(&$form, $form_state, $form_id)
contributions/cck/modules/optionwidgets/optionwidgets.module, line 11

Description

Implementation of hook_form_alter.

Code

<?php
function optionwidgets_form_alter(&$form, $form_state, $form_id) {
  // Provide additional help for the field settings form.
  if ($form_id == 'content_field_edit_form' && isset($form['widget'])) {
    $widget_type = $form['#field']['widget']['type'];
    $field_type = $form['#field']['type'];
    $label = $form['#field']['widget']['label'];

    $output = '<p>'. t('Create a list of options as a list in <strong>Allowed values list</strong> or as an array in PHP code. These values will be the same for %field in all content types.', array('%field' => $label)) .'</p>';

    if ($widget_type == 'optionwidgets_onoff') {
      $output .= '<p>'. t("For a 'single on/off checkbox' widget, define the 'off' value first, then the 'on' value in the <strong>Allowed values</strong> section. Note that the checkbox will be labeled with the label of the 'on' value.") .'</p>';
    }
    elseif ($widget_type == 'optionwidgets_buttons') {
      $output .= '<p>'. t("The 'checkboxes/radio buttons' widget will display checkboxes if the multiple values option is selected for this field, otherwise radios will be displayed.") .'</p>';
    }

    if (in_array($field_type, array('text', 'number_integer', 'number_float', 'number_decimal'))
    && in_array($widget_type, array('optionwidgets_onoff', 'optionwidgets_buttons', 'optionwidgets_select'))) {
      $form['field']['allowed_values_fieldset']['#collapsed'] = FALSE;
      $form['field']['allowed_values_fieldset']['#description'] = $output;

      // If no 'allowed values' were set yet, add a remainder in the messages area.
      if (empty($form_state['post'])
      && empty($form['field']['allowed_values_fieldset']['allowed_values']['#default_value'])
      && empty($form['field']['allowed_values_fieldset']['advanced_options']['allowed_values_php']['#default_value'])) {
        drupal_set_message(t("You need to specify the 'allowed values' for this field."), 'warning');
      }
    }
  }
}
?>