2011-07-29 27 views
0

我一直被困在天裏,我希望有人能幫助我。 我正在寫一個模塊鏈接到不同的節點(我明白,這樣的模塊確實存在,但是我想練習編寫一個模塊,我確實嘗試過看其他模塊以供參考,但是,我找不到任何問題)。Drupal 7字段多值刪除和顯示

我添加模塊後,激活自定義節點類型中的字段並選擇允許多個值。當我添加(該內容類型的)內容時,出現兩個字段而不是一個字段,並且當我添加額外字段時,我無法刪除。我希望有人能給我一些指導如何解決這個問題。我在下面列出了一個問題的截圖。我也希望添加一個刪除按鈕/一種方法來刪除一個額外的項目。經過幾天的研究後,我找不到一種drupal方式來做到這一點。

下面是我添加了參考 爲belong_to_relation.install代碼,添加以下

function belong_to_relation_field_schema ($field) { 
if ($field['type'] == 'belong_to_relation') { 

// Declare fields in the db 
$columns = array (
    'to_node_type' => array (
    'type' => 'varchar', 
    'length' => '64', 
    'not null' => FALSE, 
    'description' => 'The relation id from the belong_to_relation table', 
), 
    'to_node_nid' => array (
    'type' => 'int', 
    'not null' => FALSE, 
    'description' => 'the node id of the to node', 
), 
    'extended_node_nid' => array (
    'type' => 'int', 
    'not null' => FALSE, 
    'description' => 'the node id of the extended field node', 
), 
); 

return array (
    'columns' => $columns, 
    'indexes' => array(), 
); 
    } 

} 

對於belong_to_relation.module,我增加了以下

function belong_to_relation_field_info() { 
return array (
'belong_to_relation_reference' => array (
    'label' => t("Belong to Relation Node Reference"), 
    'description' => t('This field stores a node reference to a node of another content type'), 
    'default_widget' => 'belong_to_relation_reference_widget', 
    'default_formatter' => 'belong_to_relation_reference_formatter', 
), 
); 
} 

function belong_to_relation_field_widget_info() { 
return array (
'belong_to_relation_reference_widget' => array (
    'label' => t('Default'), 
    'field types' => array ('belong_to_relation_reference'), 
), 
); 
} 

function belong_to_relation_field_widget_form (&$form, &$form_state, $field, 
               $instance, $langcode, $items, 
               $delta, $element) { 

$element += array(
    '#type' => 'fieldset', 
    '#tree' => true 
);  

$element['to_node_type'] = array (
'#type' => 'select', 
'#title' => t('Target Node Type'), 
'#options' => array(), 
'#default_value' => isset($item['to_node_type']) ? $item['to_node_type'] : NULL, 
'#empty_option' => 'Select a Node type', 
); 

$element['to_node_nid'] = array (
'#type' => 'select', 
'#title' => t('Target Node Type'), 
'#options' => array(), 
'#default_value' => isset($item['to_node_nid']) ? $item['to_node_nid'] : NULL, 
'#empty_option' => 'Select a Node', 
); 

$element['extended_node_nid'] = array (
'#type' => 'select', 
'#title' => t('Target Node Type'), 
'#options' => array(), 
'#default_value' => isset($item['extended_node_nid']) ? $item['extended_node_nid'] : NULL, 
'#empty_option' => 'Select a Node type', 
); 

return $element; 
} 

function belong_to_relation_field_is_empty ($item, $field) { 
    return FALSE; 
} 

function belong_to_relation_field_formatter_info() { 
    return array (
    'belong_to_relation_reference_formatter' => array (
     'label' => t('Simple Belong To Relation Formatter'), 
     'field types' => array ('belong_to_relation_reference'), 
    ), 
); 
} 

我目前的Drupal 7.7運行在MAMP上。

+1

解決,需要刪除,如果($場[ '型'] == 'belong_to_relation') line in .install – user866807

+0

您可以發佈自己的答案作爲此問題的接受答案。請參閱http://meta.stackexchange.com/questions/83432/what-is-the-best-way-to-answer-your-own-question – nmc

回答

0

的OP寫道:

解決,需要刪除if ($field['type'] == 'belong_to_relation').install

+0

([在評論中回覆並轉換爲社區維基答案]( http://meta.stackoverflow.com/questions/251597/question-with-no-answers-but-issue-solved-in-the-comments?rq=1))。 –