1

What is the correct way to add a link to a menu? I am using Drupal 7 and admin menu module. I would like to add a link to the content menu item so it would be Content

Content
Add Content
Comments

I created a custom module and in the menu hook I put:

$items['admin/content/add'] = null;

Then in the menu_alter hook I put:

$items['admin/content/add'] = $items['node/add'];

Now the menu link appears where I want and when I click browser takes me to the admin/content/add but instead of showing the different options for creating node there's a text saying: You have not created any content types yet. Go to the content type creation page to add a new content type.

If I go to node/add I can see the different options to add different nodes.

So my approach seems to be wrong. What would be the correct way of adding a link to existing path into admin menu?

2

I think the easiest way to do this would be to create a fully fledged menu item and simply forward it on to the node/add page using drupal_goto() as the page callback:

function MYMODULE_menu() {
  $items['admin/content/add'] = array(
    'title' => 'Add Content',
    'access arguments' => array('administer nodes'),
    'page callback' => 'drupal_goto',
    'page arguments' => array('node/add'),
    'weight' => 10 // Use this property to control where in the menu the item will appear.
  );
  return $items;
}
  • I noticed that this way the link shows up in the admin menu only for user 1. For other users the link is not shown (although their role have all the permissions including 'administer content' permission and if they go to url admin/content/add they see the page). Any ideas? – jjei Apr 13 '12 at 14:15
  • I marked this solution not the right one as it has the problem explained in the previous comment. – jjei Apr 16 '12 at 6:57
  • 1
    Sorry my bad, the correct permission is "administer nodes", not "administer content". – Clive Apr 16 '12 at 8:03
  • Thanks, this seems to work. However, I don't understand why 'administer nodes' work and 'administer content' doesn't. In admin/people/permissions I can't even find a permission 'administer nodes'. And also I can't see why 'administer content' didn't work since the role has this permission. – jjei Apr 23 '12 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.