You are here

function multiselect_form_alter in Multiselect 7

Same name and namespace in other branches
  1. 6 multiselect.module \multiselect_form_alter()

Implements hook_form_alter().

File

./multiselect.module, line 56
Allows users to select multiple items in an easier way than the normal node-reference widget.

Code

function multiselect_form_alter(&$form, &$form_state, $form_id) {

  // Provide additional help for the field settings form.
  switch ($form_id) {
    case 'field_ui_field_edit_form':
      if (isset($form['instance']['widget'])) {
        $widget_type = $form['instance']['widget']['type']['#value'];
        $field_type = $form['#field']['type'];
        $label = $form['instance']['label']['#default_value'];
        if (in_array($widget_type, array(
          'multiselect',
        ))) {
          if (in_array($field_type, array(
            'list',
            'list_number',
            'list_text',
            'taxonomy_term_reference',
          ))) {

            // CCK user_reference and node_reference fields don't need allowed values list.
            // For other field types, if no 'allowed values' were set yet, add a reminder message.
            if (empty($form['field']['settings']['allowed_values']['#default_value'])) {
              drupal_set_message(t("You need to specify the 'allowed values' for this field."), 'warning');
            }
          }
        }
      }
      break;
  }
}