要創建內容的動態類型在Drupal 7,你將需要遵循以下流程:
更新*
1)使用hook_menu創建菜單路徑(),它採用drupal_get_form ()。這將允許您爲動態內容創建收集用戶輸入的所有數據。
例子:
$items['newpost'] = array(
'title' => 'Create Post',
'description' => 'The main noticeboard',
'page callback' => 'drupal_get_form',
'page arguments' => array('customvishal_create_content'),
'access callback' => TRUE,
);
return $items;
2)然後使用:
function customvishal_create_content($form, &$form_submit) // To create your form on that page
function customvishal_create_content_validate($form, &$form_state) // for any kind of validation
function customvishal_create_content_submit($form, &$form_state)
- 在這個功能可以提交值到新的內容類型。
- 以下是您將調用以下功能的地方。
3)創建一個數組,它將保存關於您的內容類型的元數據。
// Define the node type.
$mystuff = array(
'type' => 'mystuff',
'name' => $t('my new Stuff'),
'base' => 'node_content',
'description' => $t('This is an example node type.'),
'body_label' => $t('Content')
);
// Set defaults.
$content_type = node_type_set_defaults($mystuff);
4)使用node_type_save()來保存/聲明你的內容類型。
node_type_save($content_type);
5)創建字段,然後附加到您的內容類型。
foreach (_mystuff_installed_fields() as $field) {
field_create_field($field);
}
// Create instances of fields.
foreach (_mystuff_installed_instances() as $instance) {
$instance['entity_type'] = 'node';
$instance['bundle'] = $mystuff['type'];
field_create_instance($instance);
}
維沙爾,感謝您的幫助,但這並不能解決我面臨的挑戰。這個想法是創建動態內容類型,創建內容類型不是這裏的挑戰。 –
關鍵是使用durpal_get_forms()我已經在帖子中進一步解釋。 –