1
votes

I have added a tab to the node edit form in Drupal 7 like this (code snippet from hook_menu implementation, irrelevant lines removed):

'node/%/products' => array(
  'title' => t('Products'),
  'page callback' => 'some_function',
  'page arguments' => array(
    1
  ),
  'access callback' => TRUE,
  'type' => MENU_LOCAL_TASK
)

The tab shows up and works, however, the page is shown in the site's default theme, not in the admin theme. Also the other tabs are missing from the page that is displayed.

I tried fixing this by including this inside an implementation of hook_admin_paths, but it didn't make a difference:

return array(
    'node/%/products' => TRUE,
);

How can I enforce my page to show in the admin theme and display the other tabs for the node edit form (such as "Edit", "Revisions" etc.) ?


EDIT: The box Use the administration theme when editing or creating content at admin/appearance is ticked, and system-defined pages such as node/%/edit display in the admin theme, but my new page does not.

3

3 Answers

2
votes

I found out what I was doing wrong. In hook_menu % is used to denote an argument; in hook_admin_paths, these have to be replaced by asterisks. The following change to my implementation of hook_admin_paths solved it:

return array(
    'node/*/products' => TRUE,
);
1
votes

On /admin/appearance page, at the bottom of the page where you set the administration menu, check the value of the tickbox "Use the administration theme when editing or creating content".

0
votes

I had the same problem and I solved with the following hook_menu :

<?php
function <mymodulename>_menu() {
  $items = array();

  $output['node/%node/mypath'] = array(
    'title' => t('Title'),
    'type' => MENU_LOCAL_TASK,
    'page arguments' => array('node', 1),
    'page callback' => 'callback_function',
    'theme callback' => 'variable_get',
    'theme arguments' => array('admin_theme'),
  )
}

function callback_function() {
  return 'My New Page.';
}

I think you need to have %node inside the path because that's the right way to "auto load" the node (Drupal take care of this) and pass it as an argument to callback_function where you can use the loaded node.