开发者

Drupal 6: How can i add a link to a hook_menu()?

I have my own module and I implemented a hook_menu, I want that one menu-item redirect (The menu has to stay active) to an existing webform page, this page is: ?q=node/add/webform.

$items['adminQuestion/create'] = array(
      'title' => t('Crear Cuestionarios'),
      'page callback' => "What i put here?",
      'page arguments'开发者_Python百科 => array('form_questionnaires'),
      'access arguments' => array('access questionnaires'),
      'type' => MENU_NORMAL_ITEM,
  );


Use drupal_goto with the path to redirect to as parameter:

$items['adminQuestion/create'] = array(
  'title' => t('Crear Cuestionarios'),
  'page callback' => 'drupal_goto',
  'page arguments' => array('node/add/webform'),
  'access arguments' => array('access questionnaires'),
  'type' => MENU_NORMAL_ITEM,
);

Also note that $items['adminQuestions'] is bad practice: URLS and paths should never be case-sensitive: in fact: in Drupal CamelCase is highly discouraged in any code.


If you mean HTTP redirect by redirect, you can simply use drupal_goto('path/to/webform') but it make no sense since you can use the webform path directly. IMO what you need is a drupal_get_form()-like API for Webform which is node_load(), so webform will be loaded in your menu path:

// Assuming webform node with nid: 237
$items['adminQuestion/create'] = array(
  'title' => t('Create Cuestionarios'),
  'page callback' => 'node_load'
  'page arguments' => array(237),
  'access arguments' => array('access questionnaires'),
  'type' => MENU_NORMAL_ITEM,
);

Webform implementation of hook_theme() takes care of theming the node to form. Alternatively you can just change webform path, if possible in your case.


Here is the answer:

$items['adminquestion/create'] = array(
  'title' => 'Crear Cuestionarios',
  'page callback' => 'questionnaires_page',
  'access callback' => TRUE,
  'type' => MENU_NORMAL_ITEM,
);


function questionnaires_page() {
    module_load_include('inc', 'node', 'node.pages');
    $output = node_add('webform');
    return $output;
}

where webform is an alias of node/add/webform. Thanks


Reading the comments, it sounds to me like you want to create a path alias to /node/add/webform. You don't need to implement hook_menu.

You create aliases at /admin/build/path/add (make sure you have the path module enabled).


Here's what I did to make an 'add node page' part of a tab group

$items['mynode/new'] = array(
    'title' => 'New Node',
    'page callback' => 'node_add',
    'page arguments' => array('my_node_type'),
    'access arguments' => array('create my_node_type content'),
    'file' => 'node.pages.inc',
    'file path' => drupal_get_path('module', 'node'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 0,
);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜