我试图在内容类型变为 "required" 之前设置它的 "title" 值。所以会发生什么是根据用户名隐藏标题字段,在填写“名字”和“姓氏”字段后,我需要获取这些值,然后将它们应用于“标题”字段,然后 drupal 声明字段是必需的。这是我到目前为止所拥有的
/**
* Implements hook_form_alter().
*/
function editorhide_form_alter(&$form, &$form_state, $form_id){
global $user;
global $fullTitle;
if($form_id == 'artist_node_form'){
if( $user->name == 'Editor'){
drupal_add_js("jQuery(document).ready(function(){
jQuery('#edit-title').hide();
});","inline");
//adding the form handler
$form['#submit'][] = "editorhide_form_submit_handler";
}
}
}
//submit form handler.
function editorhide_form_submit_handler ($form, &$form_state) {
global $fullTitle;
$fullTitle = $form_state['values']['field_firstname']['und']['0']['value'];
$fullTitle .= ' '. $form_state['values']['field_lastname']['und']['0']['value'];
form_set_value($form['#edit-title'], $fullTitle,$form_state);
}
使用我当前的实现,它并没有完全满足我的要求,因为它抛出了“必填字段”错误。