2010-05-12 2 views
1

drupal_get_form을 노드 데이터를 전달할 수 없었습니다. 코드 스 니펫은 아래에 있습니다. drupal_get_form 문서 (api.drupal.org)는 추가 매개 변수를 전달합니다. 나는 분명히 $ node [ '언어']가 $ form [ 'qqq']이 만들어지지 않아서 미리보기 버튼이 나타나는 hook_form에 정의되어 있지 않기 때문에 전달되지 않은 노드 데이터를 기반으로하고있다.drupal_get_form이 노드 배열을 따라 전달하지 않습니다.

내 목표는 "노드/추가/작성자"경로를 사용하여 미리보기 버튼을 표시하지만 "milan/author/add"에는 표시되지 않는다는 것입니다. 이 목표를 달성하기위한 다른 방법이 도움이 될 수 있지만 내가 대답하고자하는 질문은 이전 단락에 있습니다. 내가 읽은 모든 것은 그것이 작동해야한다는 것을 나타냅니다.

이 메뉴 항목

 
$items['milan/author/add'] = array(
    'title' => 'Add Author', 
    'page callback' => 'get_author_form', 
    'access arguments' => array('access content'), 
    'file' => 'author.pages.inc', 
); 

전화

 
function get_author_form() { 
    //return node_form(NULL,NULL); 
    //return drupal_get_form('author_form'); 
    return author_ajax_form('author'); 
} 

function author_ajax_form($type) { 
    global $user; 
    module_load_include('inc', 'node', 'node.pages'); 

    $types = node_get_types(); 
    $type = isset($type) ? str_replace('-', '_', $type) : NULL; 
    // If a node type has been specified, validate its existence. 
    if (isset($types[$type]) && node_access('create', $type)) { 
    // Initialize settings: 
    $node = array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, 'language' => 'bbb','bbb' => 'TRUE'); 
    $output = drupal_get_form($type .'_node_form', $node); 
    } 

    return $output; 
} 

그리고 여기가이 코드 메뉴 경로는이 주제 (PHPTemplate)과 일치

 
function author_form_author_node_form_alter(&$form, &$form_state) { 
    $form['author']=NULL; 
    $form['taxonomy']=NULL; 
    $form['options']=NULL; 
    $form['menu']=NULL; 
    $form['comment_settings']=NULL; 
    $form['files']=NULL; 
    $form['revision_information']=NULL; 
    $form['attachments']=NULL; 
    if($form["qqq"]) { 
     $form['buttons']['preview']=NULL; 
    } 
} 

function author_form(&$node) { 
    return make_author_form(&$node); 
} 


function make_author_form(&$node) { 
    global $user; 
    $type = node_get_types('type', $node); 

    $node = author_make_title($node); 
    drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t($node->title), 'node/' . $node->nid))); 


    $form['authorset'] = array(
     '#type' => 'fieldset', 
     '#title' => t('Author'), 
     '#weight' => -50, 
     '#collapsible' => FALSE, 
     '#collapsed' => FALSE, 
    ); 

    $form['author_id'] = array(
    '#access' => user_access('create pd_recluse entries'), 
    '#type' => 'hidden', 
    '#default_value' => $node->author_id, 
    '#weight' => -20 
); 



    $form['authorset']['last_name'] = array(
    '#type' => 'textfield', 
    '#title' => t('Last Name'), 
    '#maxlength' => 60, 
    '#default_value' => $node->last_name 
); 

    $form['authorset']['first_name'] = array(
    '#type' => 'textfield', 
    '#title' => t('First Name'), 
    '#maxlength' => 60, 
    '#default_value' => $node->first_name 
); 

    $form['authorset']['middle_name'] = array(
    '#type' => 'textfield', 
    '#title' => t('Middle Name'), 
    '#maxlength' => 60, 
    '#default_value' => $node->middle_name 
); 

    $form['authorset']['suffix_name'] = array(
    '#type' => 'textfield', 
    '#title' => t('Suffix Name'), 
    '#maxlength' => 14, 
    '#default_value' => $node->suffix_name 
); 

    $form['authorset']['body_filter']['body'] = array(
     '#access' => user_access('create pd_recluse entries'), 
     '#type' => 'textarea', 
     '#title' => 'Describe Author', 
     '#default_value' => $node->body, 
     '#required' => FALSE, 
     '#weight' => -19 
    ); 


    $form['status'] = array(
    '#type' => 'hidden', 
    '#default_value' => '1' 
); 

    $form['promote'] = array(
    '#type' => 'hidden', 
    '#default_value' => '1' 
); 

    $form['name'] = array(
    '#type' => 'hidden', 
    '#default_value' => $user->name 
); 

    $form['format'] = array(
    '#type' => 'hidden', 
    '#default_value' => '1' 
); 


    // NOTE in node_example there is some addition code here not needed for this simple node-type 
    $thepath='milan/author'; 
    if($_REQUEST["theletter"]) { 
    $thepath .= "/" . $_REQUEST["theletter"]; 
    } 

    if($node['language']) { 
    $thepath='milan/authorajaxclose'; 
    $form['qqq'] = array(
     '#type' => 'hidden', 
     '#default_value' => '1' 
    ); 
    } 

    $form['#redirect'] = $thepath; 

    return $form; 
} 

하는 hook_form 및 hook_form_alter 코드

 
    

답변

1

make_author_form 함수의 4 행에서 기본 프로그래밍 오류가 발생했습니다. 나 자신 $ 노드 변수를 제로 아웃했다.

1

이것은 실제로는 아닐지 모르지만 을 객체 (제목)에 사용하고 배열을 사용하여 (언어를 가져 오기 위해) make_author_form() 메소드에서 사용하는 것을 볼 수 있습니다. $node이 객체 인 경우, 그 이유는 $node['language']을 검색 할 수없는 이유를 설명합니다.

내가 무엇을 하려는지 완전히 이해하고 있는지 확실하지 않지만 페이지 인수를 사용하는 것이 좋습니다.

function mymodule_form_alter($form_id, &$form) { 
    // If $form_id is {node->type}_node_form 
    // Then, check for the first argument in the URL and hide/show Preview accordingly 
} 
+0

이것은 나쁜 생각은 아니지만 문제는 아닙니다. 그것은 코드의 특정 부분을 반복해서 다시 작성하는 것을 쌓아 놓은 벼랑이었다. – ElectronicBlacksmith