2

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' => array('form_questionnaires'),
      'access arguments' => array('access questionnaires'),
      'type' => MENU_NORMAL_ITEM,
  );
berkes
  • 26,996
  • 27
  • 115
  • 206
McSas
  • 2,224
  • 3
  • 27
  • 42

5 Answers5

3

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.

berkes
  • 26,996
  • 27
  • 115
  • 206
  • Is there a way to make the menu does not collapse when I click on that link? – McSas Mar 30 '11 at 13:48
  • Why should a menu collapse when you click on it? You probably mean that the menu should remain "active" on the page where you are redirected to? If so: redirecting is not what you want in the first place. Then please update your question. Instead, you want an alias/duplicate menu-item: a menu-item that acts like another menu-item; which is something completely different then a redirect. – berkes Mar 30 '11 at 14:15
  • Yes,i want that the menu remains active when i 'm in the other page like a node_load function. i don't use node_load beacuse i don't know the nid. – McSas Mar 30 '11 at 14:36
  • 2
    actually, according to the drupal coding standards http://drupal.org/coding-standards you are supposed to use camel case on specific cases, like class names. – Peter Carrero Mar 30 '11 at 15:35
  • Your answer is the only one that works for me on Drupal 7. Thank you a lot! – Roger Jul 05 '13 at 12:40
1

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.

sepehr
  • 17,110
  • 7
  • 81
  • 119
  • How I can find out the nid of the webform's create page? – McSas Mar 30 '11 at 13:53
  • AFAIK webform has its own node type, just go to `admin/content/node`, find your webform node and check its nid. (check the edit url for example) – sepehr Mar 30 '11 at 21:20
  • Is not a webform, is a webform admin page (node/add/webform). – McSas Mar 31 '11 at 17:44
  • So simply enable the path module and go to `admin/build/path`, then create a `adminQuestion/create` alias for `node/add/webform`. – sepehr Mar 31 '11 at 23:40
  • Thanks for all the comments, i made the alias but i don't know how to call the alias from the hok_menu... – McSas Apr 01 '11 at 12:18
  • Santiago, Please exactly explain what you want to do, so we can help you more effectively. I have no clue about why you need to "call" an alias in the implementation of hook_menu(). Please be more specific. – sepehr Apr 01 '11 at 17:08
  • how i call an Alias from the hook_menu() item?: `$items['adminQuestion/create'] = array( $items['adminQuestion/create'] = array( 'title' => t('Create Cuestionarios'), 'page callback' => -->"What i put here?"<--, 'page arguments' => array('form_questionnaires'), 'access arguments' => array('access questionnaires'), 'type' => MENU_NORMAL_ITEM, );` – McSas Apr 01 '11 at 17:31
1

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

McSas
  • 2,224
  • 3
  • 27
  • 42
0

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,
);
Carl von Buelow
  • 1,154
  • 7
  • 11
0

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).

joejoejoew
  • 36
  • 1
  • i need the hook_menu beacuse is part of a bigger module. i don't know how to load a page that doesn't have a nid beacuse is a webform admin page. – McSas Mar 31 '11 at 17:47