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.
The module could do with an option to add <a href="#anchor-name"></a
> for a 'back to top' link that you can create in a footer menu.
Currently creating a <nolink>
just renders <span title="" class="nolink">top</span>
where as it needs to be <a href="#main-content"></a>
The HTML.tpl for the bootstrap base theme for example has <a href="#main-content" class="element-invisible element-focusable"><?php print t('Skip to main content'); ?></a>
so this will provide any easy back to top link on all site pages.
I cant change the setting for <nolink>
markup as the top menu uses the span tag extensively.
Comment | File | Size | Author |
---|---|---|---|
#4 | special_menu_items-anchor_item-2317329-4.patch | 5.05 KB | rooby |
Comments
Comment #1
erg-web CreditAttribution: erg-web commentedComment #2
erg-web CreditAttribution: erg-web commentedComment #3
rooby CreditAttribution: rooby commentedI agree this needs to be separate from the ability to change the nolink markup.
There would need to be something like a menu path for
'<anchor>'
and then another entirely new field to store the anchor itself.The menu_links database table has a column for options, which is for options to pass into l()/url(), which seems like a good place to actually store the data.
Comment #4
rooby CreditAttribution: rooby commentedHere is a patch for this.
It must be applied over the top of the patch in #2325075: Add select options instead of making the user enter strange link paths
I'm wondering if maybe it should be named more specifically, like
<current-anchor>
or something seeing as it is specifically a current page anchor.Although I think if we wanted to give full anchor support we are getting a little out of scope of this module and probably should be making a different module that just exposes fields for fragment & query.
Comment #5
rooby CreditAttribution: rooby commentedComment #6
futuredesignUK CreditAttribution: futuredesignUK commentedgreat! sorry new to Drupal - how do I apply a patch to a module?
Comment #7
rooby CreditAttribution: rooby commentedIt depends on your operating system.
These are the main docs for it: https://www.drupal.org/patch/apply and there are links off that page for windows/mac specific information.
If none of those solutions seem feasible for you or you can't get it to work or anything I can post a zip file of the whole module.
Comment #8
Sherbet CreditAttribution: Sherbet commentedrooby, thanks for your effort in making this patch. It works great! Thus far there's only one suggestion I have, which is to strip whitespace from before the anchor text (e.g. ' anchorname' gets put out as '# anchorname').
Hopefully this gets added to the module soon, because it's a very welcome addition.
Comment #9
erg-web CreditAttribution: erg-web commentedThanks
I applied both patches using git (as under GIT)
patch < file.patch
special_menu_items-menu_item_type_selection-2325075-1.patch
and then
special_menu_items-anchor_item-2317329-4.patch
But now my drupal site brings up the error?
Comment #10
das-peter CreditAttribution: das-peter at Cando commentedThe current implementation of anchors always points to the frontpage, is this really what we want?
url('', array('fragment' => 'frag'))
=/#frag
We could point to the current page using this pattern:
url('', array('fragment' => 'frag', 'external' => TRUE))
=#frag
Edit: I might should mention that we use language negotiation based on language prefix. That might has an effect on
url('')
.Comment #11
rooby CreditAttribution: rooby commented@das-peter:
True, there's no reason not to also allow a path.
I don't think that the external flag is necessary though, I think it should work like the path field normally does and have the user input the full URL if they want external, otherwise it is relative.
Comment #12
das-peter CreditAttribution: das-peter at Cando commented@rooby Indeed, it would be nice to be able to use a path as well (e.g.
node/123#video
). On submit we can split the input usingparse_url()
to get the path / fragment separated.However, if no path is given and which, in my eyes, should act as "on the current site" using
url('')
still will point to the frontpage - to change that we have to do some handling ( and I just figured setting the external flag is the easiest way to get the intended behaviour).Comment #13
rooby CreditAttribution: rooby commentedYeah I totally forgot about the current page thing. Probably should have read the title haha.