0
我想創建我的第一個創建簡單節點類型wcNames的drupal模塊。此節點類型有兩個字段,名字爲&姓氏。 我可以讓我的模塊創建節點類型的數據庫表,並將其添加到node_type表中,但是當我打開node/add/wc-name字段時,名字和姓氏不會出現。 以下是我的代碼。請建議。我的節點類型不會顯示它的字段
<?php
// wc_name.install file
/*
* hook_schema Implementation: Creates the DB and it's fields
*/
function wc_name_schema(){
$schema['wc_name_names'] = array(
'fields' => array(
'nmid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
'firstname' => array('type' => 'varchar', 'length' => 50, 'not null' => FALSE),
'lastname' => array('type' => 'varchar', 'length' => 50, 'not null' => FALSE),
),
'primary key' => array('nmid'),
'unique keys' => array(),
'indexes' => array(
'nmid' => array('nmid'),
),
);
return $schema;
}
//function wc_name_install(){ } // Use this function to set variables for the module.
function wc_name_uninstall(){
//unset variables if any set
// Delete all wc_name nodes
db_delete('node')->condition('type', 'wc_name')->execute();
// Delete all wc_name tables
db_drop_table('wc_name_names');
}
?>
<?php
// wc_name.module
/*
* Implementation of _node_info(): define node
*/
function wc_name_node_info(){
return array(
'wc_name' => array(
'name' => t('wcName'),
'base' => 'wc_name',
'base' => 'page',
'description' => t("A smaple module to save names."),
'has_title' => TRUE,
'title_label' => t('Title'),
'has_body' => FALSE,
)
);
}
function wc_name_menu() {
$items = array();
$items['wc_name'] = array(
'title' => 'wcNames',
'page callback' => 'wc_name',
// 'access arguments' => array('access wcNames'),
);
}
?>
<?php
// wc_name_form.inc
function wc_name_form($node, &$form_state){
// Add fields
$form['first_name'] = array(
'#type' => 'textfield',
'#title' => t('First name'),
'#required' => FALSE,
'#default_value' => $node->wc_name['firstname'],
);
$form['last_name'] = array(
'#type' => 'textfield',
'#title' => t('Last name'),
'#required' => FALSE,
'#default_value' => $node->wc_name['lastname'],
);
return $form;
}
?>
我錯過了什麼?
這是創建一個模塊時,這樣的標準Drupal的方式嗎?包括這段代碼給了我「例外:theme()可能不會被調用,直到所有的模塊都被加載。」theme()「 – Nick 2013-02-18 11:37:53
你在哪個事件中創建節點類型? – 2013-02-18 12:29:24
在我的origianl文件中,將wc_name_form()移動到.module文件解決了問題。 將其保存在wc_name_form.inc中時,它應該與.module文件中包含的效果相同。 反正,問題解決了。 – Nick 2013-02-18 14:00:25