Drupal 7 开发内部培训资料, 分头诗人

关于VBO中传值的问题

赞成!
0
否决!

各位我的案例中是这样的:

在一个仓库的数量中进行对余下的数量进行批理扣数,扣数时需要加入日期。

现在定义一个

 

function fabric_base_vbo_action_info(){return array(

  'fabric_base_vbo_action'=>array(
   'type'=>'entity',
   'label'=>t('批量出仓'),
   'behavior'=>array('change_property'),
   'configurable'=>FALSE,
   'vbo_configurable'=>TRUE,
   'triggers'=>array('any'),
   'permissions'=>array('fabric base vbo','storage vbo'),
  ),
);
}
function fabric_base_vbo_action_views_bulk_operations_form($options){
	  $form=array();
	  $form['vbo']['select']= array(
		'#type' => 'select',
		'#title' => t('批量操作选项'),
		'#options'=>array(
			'AllSelect'=>t('余量出仓'),
			'Something'=>t('部分出仓'),
			),
		'#default_value'=>!empty($options['vbo']['select'])?$options['vbo']['select']:'',
		
		);
		$form['vbo']['num']=array(
			
			'#type'=>'textfield',
			'#title'=>t('数量'),
			'#default_value'=>0,
			'#size'=>60,
			
		);
	 return $form;
 }
function fabric_base_vbo_action_form($settings,&$form_state){	
	 dpm($form_state);
	 
	 $form=array();	 
	 $form['vbo']['select']= array(
		'#type' => 'select',
		'#title' => t('批量操作选项'),
		'#options'=>array(
			'AllSelect'=>t('余量出仓'),
			'Something'=>t('部分出仓'),
			),
		'#default_value'=>isset($settings['settings']['vbo']['select'])?$settings['settings']['vbo']['select']:'',
		
		);
		$form['vbo']['num']=array(
			
			'#type'=>'textfield',
			'#title'=>t('数量'),
			'#default_value'=>0,
			'#size'=>60,
			
		);
	 return $form;
 }

接下来这个Sumbit就是问题所在:

 function fabric_base_vbo_action_submit($form,$form_state){	 	
      $return =array();
	  dpm($form_state);
	  switch ($form_state['complete form']['vbo']['select']['#value'])
	  {
		  case 'AllSelect':
			$return=array(
				//这里要如何向action进行传值?
			);
		  break;
		  case 'Something':
			
		  break;
		  default:break;
	  }
	 	 
		 return $return;
 }
	function fabric_base_vbo_action(&$entity,$contex){
	  dpm($entity);
	  dpm($contex);
	  //$query=db_update('my_field')...

	}   

现在是我不确定在sumbit中如何向action传一个nid的值给action进行更新我的数据?

5 个回答

赞成!
0
否决!

一个例子

function assign_to_action_submit($form,$form_state){
    watchdog('views','Submit action',array(),WATCHDOG_DEBUG);
    $return = array();
    $return['uid'] = $form_state['values']['uid'];
    return $return;
}

function assign_to_action(&$node,$contex t){
    watchdog('views','Execute action',array(),WATCHDOG_DEBUG);
    #get settings fieldname
    $field = $contex t['settings']['fieldname'];
    #get user from context
    $user = user_load($context['settings']['uid']);
    #field_set_value($node,$field,$user);
    drupal_set_message("Got field ".$field." and user ".$user);
}
赞成!
0
否决!

这里的关键是,我的Value想当于这里的$form_state['value']['uid']中的值是要通过选择的nid 来取,当前这会,怎么来确定在nid的列表中的位置?

赞成!
0
否决!

可能是我漏了什么没有看,我再了解下$form_state['values']['uid'];这个东西,我在DPM中没有认真看到的东西,我再去找找。

赞成!
0
否决!
function fabric_base_vbo_action_submit($form,$form_state){	 	
      $return =array();
	  dpm($form_state);
	  
	  switch ($form_state['complete form']['vbo']['select']['#value'])
	  {
		  case 'AllSelect':
			foreach (array_keys($form_state['selection']) as $selectid){
				$data[]=array(
					'yardage'=>$form_state['bulid_info']['args'][0]->result[$selectid]->field_field_warehosestorageio[0]['raw']['value'];
				);
			}
			$return=array(
				'nid'=>$form_state['selection'],
				'yardage'=>$data,				
				);
		  break;
		  case 'Something':
			foreach (array_keys($form_state['selection']) as $selectid){
				if((int)$form_state['bulid_info']['args'][0]->result[$selectid]->field_field_warehosestorageio[0]['raw']['value']-(int)$form_state['values']['num']>0){
					$data[]=array(
					'yardage'=>$form_state['values']['num'],
					'io'=>(int)$form_state['bulid_info']['args'][0]->result[$selectid]->field_field_warehosestorageio[0]['raw']['value']-(int)$form_state['values']['num'],
					);
				}
				else{
					$data[]=array(
					'yardage'=>$form_state['bulid_info']['args'][0]->result[$selectid]->field_field_warehosestorageio[0]['raw']['value'],	
					'io'=>0,
					);
				}				
			}
			return=array(
				'nid'=>$form_state['selection'],
				'yardage'=>$data,							
			);
		  break;
		  default:break;
	  }
	 	 
		 return $return;
 }

 

我只想到这样的做法,我这里成了数组传递,直接传数据,不知道怎么去做成单一值的传递呢?

赞成!
0
否决!

我想通了,上面的方法错了,这位置不是取值的地方,在submit只是提交下我的配置,真正要取值是在后面的Action中去做。