カスタム コンテンツ タイプ - ノードを drupal 6.26 を使用して drupal データベースに保存しようとしています。スキーマ テーブルは既に作成しましたが、フォームの送信ボタンを実行すると、次のエラーが発生しました。
ユーザー警告: キー 'PRIMARY' クエリの重複エントリ '0-0' ) VALUES (0, 0, 0, '', '', '', 0, '', 0, 0, 0 ) /var/www/drupal/modules/service/service.module の 261 行目。
少なくともエントリはデータベースに保存されておらず、入力した nid 、 vid 、 uid も他の値も利用できないようです。
$node を渡す方法は正しいですか?
function service_form(&$node) {
function service_form_submit($node) {
$node? をどのように使用するかの完全なコード
<?php
/**
* Implementation of hook_node_info().
*/
function service_node_info() {
// We return an array since a module can define multiple node types.
return array(
'service' => array(
'name' => t('Service'), // Required.
'module' => 'service', // Required. Prefix of the callback functions to look for: service_validate(), service_insert(), service_delete()
'description' => t('Offer your service to the church.'), // Required.
'has_title' => TRUE,
'title_label' => t('Please enter your Service Name'),
'has_body' => TRUE,
'body_label' => t('Service Description'),
'min_word_count' => 2,
'locked' => TRUE
)
// todo here we add more node types later
);
}
function service_form(&$node) {
// Get metadata for this node type
// (we use it for labeling title and body fields).
// We defined this in service_node_info().
$type = node_get_types('type', $node);
$form['general'] = array(
'#type' => 'fieldset',
'#title' => t('General Service Information')
);
// service name
$form ['general']['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label), // 'Service Name', //
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => -5,
'#maxlength' => 255,
);
// service description
$form ['general']['body_filter']['body'] = array(
'#type' => 'textarea',
'#title' => check_plain($type->body_label), // 'Service Description', //
'#default_value' => $node->body,
'#rows' => 6,
'#required' => TRUE
);
// Filter options
// $form['body_filter']['filter'] = filter_form($node->format);
// todo replace with taxonomy - ask forum
$form ['general'] ['category'] = array(
'#multiple' => '0',
'#required' => '1',
'#key_type_toggled' => '0',
'#description' => t('Category of the service '),
'#default_value' => isset($node->category) ? $node->category : '',
'#weight' => '3',
'#type' => 'select',
'#options' => array(
'1' => t('Apostelservice'),
'2' => t('Social Service'),
'3' => t('Praying Service'),
),
'#multiple_toggle' => '1',
'#title' => t('Category'),
);
$form['availabilty'] = array(
'#type' => 'fieldset',
'#title' => t('Service Availabilty') ,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form ['availabilty'] ['service_start'] = array(
'#type' => 'date_popup',
'#title' => t('Start service on'),
'#size' => 20,
'#maxlength' => 20,
'#default_value' => isset($node->service_start) ? $node->service_start : '',
);
$form['availabilty']['service_stop'] = array(
'#type' => 'date_popup',
'#title' => t('Terminate Service at'),
'#size' => 20,
'#maxlength' => 20,
'#default_value' => isset($node->service_stop) ? $node->service_stop : '',
);
// fallback service
$form ['availabilty']['fallback_service'] = array(
'#multiple' => '1',
'#required' => '0',
'#key_type_toggled' => '0',
'#description' => t('Choose a fallback services to avoid bottlnecks'),
'#default_value' => array(
'0' => '1',
),
'#type' => 'select',
'#options' => array(
'1' => t(' random / no fallback service'),
'2' => t(' Fallback Service 2'),
'3' => t(' Fallback Service 3'),
),
'#multiple_toggle' => '1',
'#title' => t('Fallback Services'),
);
$form ['availabilty']['blocked'] = array(
'#default_value' => array(
),
'#required' => '0',
'#key_type_toggled' => '0',
'#description' => t('The service can be disabled - blocked due to different reasons e.g. misuse, clarification needed'),
'#weight' => '1',
'#type' => 'checkboxes',
'#options' => array(
'one' => t('Block Service'),
),
'#title' => t('Block Service'),
);
$form ['availabilty']['reason_blocked'] = array(
'#required' => '0',
'#input_format' => '1',
'#description' => t('Please enter a reason why the Service is disabled, if this is the case.'),
'#weight' => '2',
'#type' => 'textarea',
'#title' => t('Reason of blocked Service'),
);
$form['location'] = array(
'#type' => 'fieldset',
'#title' => t('Service location information')
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Register your service'),
);
return $form;
}
**
* Handle submission of the service form and saving
* of the data to the database.
*/
function service_form_submit($node) {
db_query("INSERT INTO {service} (nid, vid,uid, fallbackservice_ids , category , biblebasic ,
blocked , reason_blocked , created , begin , stop) VALUES (%d, %d, %d, '%s', '%s', '%s', %d, '%s', %d, %d, %d )",
$node->nid, $node->vid,$node->uid, $node->fallbackservice_ids, $node->category,
$node->biblebasic, $node->blocked, $node->reason_blocked, $node->created, $node->begin, $node->stop);
}
?>