You are here

function multiselect_form_alter in Multiselect 6

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

Implementation of hook_form_alter().

File

./multiselect.module, line 25
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.
  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 (in_array($widget_type, array(
      'multiselect_select',
    ))) {
      if (in_array($field_type, array(
        'text',
        'number_integer',
        'number_float',
        'number_decimal',
      ))) {
        $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');
        }
      }
    }
  }
}