Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 839615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:29:36+00:00 2026-05-15T05:29:36+00:00

Is there a way to set a limit on how many menu items users

  • 0

Is there a way to set a limit on how many menu items users can add to Primary Links menu? I’m working on a Drupal site and I have a horizontal primary links nav bar. There is only room for no more than 7-8 links in the nav bar. I don’t want the future maintainer of the site to add more than 8 items to the menu. Is there a way I can set a limit on that? Some module or override function?
Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:29:37+00:00Added an answer on May 15, 2026 at 5:29 am

    You could try this:

    http://api.drupal.org/api/function/menu_primary_links/6

    Then, using hook_form_alter, do:

    $menu_links = count(menu_primary_links());
    
    if ($menu_links > 8) {
       unset($form['menu']);
    }
    

    But, we must also protect nodes that are already in the menu. So,

    $menu_links = count(menu_primary_links());
    
    if ($menu_links > 8 && !($form['menu']['mlid']['#value'] != 0 && $form['menu']['#item']['menu-name'] == 'primary-links')) {
       unset($form['menu']);
    }
    

    That will remove the menu option from a node form only if that node has no existing menu entry in primary links menu. It checks by looking to see if the node you are editing has an mlid, and if so, if it is in the primary links menu.

    hook_form_alter http://api.drupal.org/api/function/hook_form_alter

    But how will our users know what happened? Lets tell them.

    if ($menu_links > 8 && !($form['menu']['mlid']['#value'] != 0 && $form['menu']['#item']['menu-name'] == 'primary-links')) {
       unset($form['menu']);
       drupal_set_message('The maximum limit of links in the primary menu has been reached.', 'status', FALSE);
    }
    

    You could expand on that message by listing $menu_links too, so the user knows which nodes need removing before other nodes can be added.

    Also, this is a little tricky if they make use of secondary links or other menus. In which case, you would need more programming to replace the tree within the menu options, but thats a bit more involved at the moment. They could always add nodes to secondary menus through Admin > Build > Menus.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.