a Drupal newbie here trying to create his first module for Drupal 7.
In my site I've created a new content type (machine name: abstract) from the site's admin's front-end. A user can add a new instance of this content type by using a form I've defined using the FAPI. In this form's submit function I do the following:
function form_add_abstract_submit($form, &$form_state) {
global $user;
$node = new stdClass();
$node->type = 'abstract';
node_object_prepare($node);
$node->title = $form_state['values']['abstract_title'];
$node->language = LANGUAGE_NONE;
$node->uid = $user->uid;
// ... fill the rest of the node's fields here [...]
if($node = node_submit($node)) {
node_save($node);
// Not sure about this way of defining the path to the created node
$path = 'abstract/' . $node->nid;
$node->path = array('alias' => $path);
node_save($node);
drupal_set_message(t('Abstract submitted');
} else {
form_set_error('description', t('ERROR'));
}
$form_state['redirect'] = 'index.php';
}
As shown above, I define the path to these nodes to be 'abstract/[its-node-id]'. Then, when a user visits this URL I'd like to show two tabs, one allowing the user to see the node's fields and another linking to a form to edit it. I've tried to implement it by adding the following three menu items in my hook_menu function:
$items['abstract/%'] = array(
'title callback' => 'abstract_page_title',
'title arguments' => array(1),
'page callback' => 'abstract_page_view',
'page arguments' => array(1),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['abstract/%/view'] = array(
'title' => 'View',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['abstract/%/edit'] = array(
'title' => 'Edit',
'page callback' => 'drupal_get_form',
'page arguments' => array('my_module_form_abstract_edit', 1),
'access callback' => TRUE,
'file' => 'my_module_forms.inc',
'type' => MENU_LOCAL_TASK,
);
However, if I visit abstract/[a-node's-id], my abstract_page_view function is not being called and the default view for rendering my content type is displayed. The 'Edit' tab on this view also links to abstract/[the-node's-id]#overlay=node/[the-node's-id]/edit, not to abstract/[the-node's-id]/edit, as I'd like to.
What am I doing wrong? Should I programmatically define my content type instead of doing it from the admin's backend or is my problem somewhere else?