Score:1

Is there a way to disable the option for menu links?

cn flag

For our unified Drupal platform, we require all of our sites main menu items to be a page and any sub-pages to show a path following the parent menu item. So if "About Us" (with a path of /about-us) is a top level menu item, it must be a page. And the page "History" under that will have a path of /about-us/history. "About Us" cannot be a <nolink> with History as a child. How can I prevent users from using the <nolink> option for menu links? The core link module includes in the description to the user of how to include the <nolink> option. That shows that if it supports internal and external links. Well, I don't want to exclude one of those for menu links in general. I'm thinking I'm going to have to do a form alter, plus some type of validation, but I'm not sure what.

It was added from this issue but they did not do a toggle the way the D7 link contrib module did. And it's a toggle I need - to turn it off in this case.

Score:1
cn flag

I'd say that I would solve this requirement by doing three things:

  1. CSS: easy one, just hide the tooltip about
  2. JavaScript: add a client-side validation that checks the value of the link field and if the '' regexp is found, prevent from saving and show a message.
  3. hook_form_alter and check for instance via route parameters if it has menu_link_content and then add your server-side validation.

Also, point 1 could be done as well in the form_alter by replacing the description there instead of via CSS.

shelane avatar
cn flag
I found the appropriate form to alter, but the form element is `link[0][uri]` and I'm not quite sure how to alter that. I tried: `$form['link'][0]['uri']['#description'] = t('my replacement text');` but that didn't work. I would also need to alter the validation.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.