1

How to hide/disable EDIT & DELETE links in menu-customize form.

www.yoursite.com/admin/build/menu-customize/primary-links

I think that those links bring more potential problems than benefits. It would be great if anyone knew how to disable them per role but a global disable is fine too. I'm using Drupal 6.

p.s. I still want user to have permission to rearrange menu items ordering.

Thanks for the help.

4
  • You could hide these links using css formatting. – Refineo Oct 14 '11 at 11:32
  • Thanks for reply. Currently they do not have any class/id i can grab on to. Maybe if i override function that generate output i'll be able to add extra classes. Do you have hint how to do that? – Nebojsa Oct 14 '11 at 11:51
  • Do you want them disabled for all menus or just primary links? – Laxman13 Oct 14 '11 at 12:56
  • Just primary-links. – Nebojsa Oct 14 '11 at 13:18
3

You can create a small custom module and implement hook_form_FORM_ID_alter(). Below is a quick example for Drupal 6:

.module file

<?php
/**
 * Implementation of hook_form_FORM_ID_alter()
 */
function YOURMODULE_form_menu_overview_form_alter(&$form, &$form_state) {
  GLOBAL $user;

  // Check if user has a certain role or not and menu is primary links
  // Change ROLEID to the role id you want operations hidden from
  if (!array_key_exists(ROLEID, $user->roles) && arg(3) == 'primary-links') {

    // Hide edit/delete menu operations
    foreach ($form as $key => $ele) {
      if (substr($key, 0, 5) == 'mlid:') {
        unset($form[$key]['operations']);
      }
    }

  }
}

Change YOURMODULE to the name of the module you are creating. For assistance creating custom modules, see the Module developer's guide.

To work in Drupal 7, I believe all you would need to do is change arg(3) to arg(4) due to the path changes.

4
  • Great stuff! Thanks! It, seams that third argument "$form_id" should be left out. – Nebojsa Oct 14 '11 at 15:06
  • Also, it seams that in condition "!" is not needed. – Nebojsa Oct 14 '11 at 15:14
  • Ah good catche, changed from hook_form_alter to hook_form_FORM_ID_alter, forgot to remove the $form_id. The "!" I used in testing on my own site. It just depends if you want to check if a user has a role or doesn't have a role. If only giving permission to see these links to one or two roles, would be easier to use ! instead of repeating array_key_exists() for each role you want them hidden from – Laxman13 Oct 14 '11 at 15:26
  • 1
    Thanks a lot. The $key => $ele and then the $form[$key] was a savior. I was trying to directly alter $ele without any luck. – cherouvim Jul 19 '12 at 12:26

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.