Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By lzande on
I am creating a custom theme for Drupal 8. I would like to have it so when the theme is installed it adds some custom text to the admin add link page for only the main menu.
For example:
The page url is /admin/structure/menu/manage/main/add?destination=/admin/structure/menu
under the link field it reads:
- The location this menu link points to.
- Start typing the title of a piece of content to select it. You can also enter an internal path such as /node/add or an external URL such as http://example.com. Enter <front> to link to the front page.
I would like it to read:
- The location this menu link points to.
- Start typing the title of a piece of content to select it. You can also enter an internal path such as /node/add or an external URL such as http://example.com. Enter <front> to link to the front page.
- Enter custom text
How can I do this, would it be a hook or what?
Comments
You just want to add some
You just want to add some text to that form? If so, you're looking for hook_form_alter() - https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21form.api.php/function/hook_form_alter/8.7.x
If, however, you're wanting to add a new field, then you probably want https://www.drupal.org/project/menu_item_extras
- Mike, from Little Blue Labs and Drupal Check
I have the following in my
I have the following in my .theme file.
The TEST string only shows up when i visit the settings page for the theme and not on all pages.
If I go to a page with a form on it, I don't see the var_dump. any ideas?
Sorry if this sounds like a simple question. I have been working with Drupal for 6 years but never had to do hooks or any module development.
EDIT: I figured it out. I had to set the admin theme of my site to the one i was working on. Looks like I will need two themes for this to work. BTW: I looked at your sites Mike, you have a lot of insight in Drupal. Thanks for your help.
I have a new issue
I have the following drupal hook in my .theme file.
The kint before line shows the original Drupal description. The kint after line shows the modified description as TEST. However, when the form renders, the default is displayed instead of the custom one.
Please see this image.
/**
Try this i was able to add the help text on links fields.
This will add one more line of help text and keep what is already present
Adding custom text to the 'Add menu link' page