I've searched around for quite a bit but can't find the anwer. I'm trying to add a "Edit this page" functionality to my admin menu. Is there an existing feature or module that I'm missing which allows an admin to go directly to editing the page being viewed?

If such a module doesn't exist, can I create one? I tried creating a link on my admin menu , but it doesn't seem to work:

function admin_edit_menu() {
     $items = array();
     $items['admin/misc'] = array(
      'menu_name' => 'management',
      'title' => 'Edit',
      'description' => 'Edit this page',
      'page callback' => 'http://www.mysite.com/node/' . $node->nid . '/edit',
      'access callback' => TRUE,
      'type' => MENU_NORMAL_ITEM,
      'weight' => -15,        
  • Thanks to Chapabu and Triskelion, I realized that I could go about achieving this another way. I installed the Menu Token module, then I was able to add the "Edit This" button to the "management" menu through Drupal's Menus and give it the link "node/[node:nid]/edit" and enabled tokens under the link, and voila I can now instantly go to the edit page of the node I'm viewing without having to browse for it. – longboardnode Feb 26 '13 at 23:10

You can probably accomplish this by using hook_menu_alter.

I have made it a practice to include a site-specific module with every site to act as a repository for any custom code.

| improve this answer | |
  • 1
    This doesn't answer the question - perhaps you could explain HOW op could use hook_menu_alter to their advantage? :) – Chapabu Feb 26 '13 at 19:00
  • It is, essentially, already done. Change the function name to mysite_menu_alter(&$items), eliminate the $items=array(); line, and place the function in an active mysite.module file. – Triskelion Feb 26 '13 at 19:27
  • @Triskelion thanks, since I'm trying to make this appear in the admin menu, won't it be admin_menu_alter? I tried it both ways but the menu item doesn't appear (cache cleared): function admin_menu_alter(&$items) { $items['admin/edit'] = array( 'menu_name' => 'management', 'title' => 'Edit', 'description' => 'Edit this page', 'page callback' => 'mysite/node' . $node->nid . '/edit', 'access callback' => TRUE, 'access arguments' => array('administer nanog misc'), 'type' => MENU_NORMAL_ITEM, 'weight' => -15, ); } – longboardnode Feb 26 '13 at 22:12
  • The drupal hook system allows modules to modify core functions like menu_alter by naming the functions as (for instance) modulename_menu_alter. This is why @Chapabu thought you were using the Admin Menu module. If you place this function in a separate module (without hacking the core or contributed modules, the module you put it in must be activated on your modules page, and the function must be named yourmodulename_menu_alter. Where are you putting this function? – Triskelion Feb 26 '13 at 22:52
  • Okay I see what you mean. I changed to mymodulename_menu_alter and the link showed up in the menu. Thanks! My only problem is that it won't point to the node being viewed but I'm accepting your answer because I didn't realize that I had two problems to solve here. See my comment to my op above about my final solution. – longboardnode Feb 26 '13 at 23:05

Assuming you're referring to the Admin menu module then you can head to the configuration page under admin/config/administration/admin_menu and under the System tweaks tab you can check the option for Move local tasks into menu.

| improve this answer | |
  • Thanks Chapabu, but I wasn't really referring to the Admin module. Although it seems useful it won't work for my client. If you have any suggestions how to make my code work with the system's default admin menu plz let me know! (BTW wasn't my downvote) – longboardnode Feb 26 '13 at 18:24
  • 1
    That's OK - sometime people feel the need to downvote answers for no reason with no explanation ;-) – Chapabu Feb 26 '13 at 18:36
  • lol So I was thinking perhaps I could just add the "edit" link through the Drupal Menu management UI (/admin/structure/menu/manage/management) instead of a hook. I entered 'node/10/edit' as the menu's link to test and it worked. But I'm not sure how to enter the current nid variable into the link... any ideas by chance? – longboardnode Feb 26 '13 at 18:56

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.