1

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.

0

1 Answer 1

1

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.

1
  • 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.
    – shelane
    Sep 3, 2021 at 3:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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