'.t("Provides an easy to use control for adding multiple items.").'
'; break; } return $output; } /** * Implementation of hook_widget_info. * Specifies the label and that it is a widget for the nodereference field type */ function multiselect_widget_info() { return array( 'multiselect_select' => array( 'label' => t('Multiselect List'), 'field types' => array('nodereference'), ), ); } /** * Implementation of hook_widget * @todo Doesn't seem to populate list when in 'preview' (see http://drupal.org/node/139595) */ function multiselect_widget($op, &$node, $field, &$items) { switch ($op) { case 'prepare form values': $items_transposed = content_transpose_array_rows_cols($items); //to avoid an error being thrown in admin/content/types/.$module_base_path.'/images/add.png) ",
        '#weight' => 1,
        '#attributes' => array('class' => 'select'),
      );
      
      $form[$field['field_name']]['deselect'] = array(
        '#type' => 'markup',
        '#submit'=> false,
        '#value' => 
          '
",
        '#weight' => 1,
        '#attributes' => array('class' => 'select'),
      );
      
      $form[$field['field_name']]['deselect'] = array(
        '#type' => 'markup',
        '#submit'=> false,
        '#value' => 
          '
            .$module_base_path.'/images/remove.png) ",
        '#weight' => 2,
      );
      return $form;
    case 'process form values':
      if ($field['multiple']) {
        //adjust perspective
        $items['nids'] = $items['selected'];
        unset($items['selected']);
        unset($items['unselected']);
        
        // if nothing selected, make it 'none'
        if (empty($items['nids'])) {
          $items['nids'] = array(0 => '0');
        }
        $items = array_values(content_transpose_array_rows_cols(array('nid' => $items['nids'])));
      }
      else {
        $items[0]['nid'] = $items['nids'];
      }
      // Remove the widget's data representation so it isn't saved.
      //  unset($items['nids']);
      foreach ($items as $delta => $item) {
        $items[$delta]['error_field'] =  $field['field_name'] .'][nids';
      }
      
    case 'validate':
  }
}
/**
 * Alters the preview form to include the newly added items
 */
function multiselect_fix_selected($field, $edit)
{
  
  if( isset($field['#post']) && !empty($field['#post'])){
  
    $field_id = $field['selected']['#attributes']['id'];
    
    
    $selected = $field['selected']['#post'][$field_id]['selected'];
    
    $field['selected']['#options'] =  array();
    $field['unselected']['#options'] =  $field['#all_options'];
    
    if ( !is_null($selected) ){
      foreach( $selected as $selected_nid )
      {
        $field['selected']['#options'][$selected_nid] = $field['#all_options'][$selected_nid];
        unset($field['unselected']['#options'][$selected_nid]);
      }
    }
  }
  
  return $field;
}
/**
 * Implementation of hook_nodeapi.
 * @todo The adding of javascript can be moved to the _widget function.
 */
function multiselect_nodeapi(&$node, $op, $teaser, $page)
{
/*  switch ($op)
  {
    case 'prepare': 
  }*/
}
          ",
        '#weight' => 2,
      );
      return $form;
    case 'process form values':
      if ($field['multiple']) {
        //adjust perspective
        $items['nids'] = $items['selected'];
        unset($items['selected']);
        unset($items['unselected']);
        
        // if nothing selected, make it 'none'
        if (empty($items['nids'])) {
          $items['nids'] = array(0 => '0');
        }
        $items = array_values(content_transpose_array_rows_cols(array('nid' => $items['nids'])));
      }
      else {
        $items[0]['nid'] = $items['nids'];
      }
      // Remove the widget's data representation so it isn't saved.
      //  unset($items['nids']);
      foreach ($items as $delta => $item) {
        $items[$delta]['error_field'] =  $field['field_name'] .'][nids';
      }
      
    case 'validate':
  }
}
/**
 * Alters the preview form to include the newly added items
 */
function multiselect_fix_selected($field, $edit)
{
  
  if( isset($field['#post']) && !empty($field['#post'])){
  
    $field_id = $field['selected']['#attributes']['id'];
    
    
    $selected = $field['selected']['#post'][$field_id]['selected'];
    
    $field['selected']['#options'] =  array();
    $field['unselected']['#options'] =  $field['#all_options'];
    
    if ( !is_null($selected) ){
      foreach( $selected as $selected_nid )
      {
        $field['selected']['#options'][$selected_nid] = $field['#all_options'][$selected_nid];
        unset($field['unselected']['#options'][$selected_nid]);
      }
    }
  }
  
  return $field;
}
/**
 * Implementation of hook_nodeapi.
 * @todo The adding of javascript can be moved to the _widget function.
 */
function multiselect_nodeapi(&$node, $op, $teaser, $page)
{
/*  switch ($op)
  {
    case 'prepare': 
  }*/
}