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.
Countless times this was requested for. The code is extremely simple and straightforward. To test this, I needed to fix the outstanding system settings file dirs bug -- such is life :) If you change the front page on admin/settings then the <front> entry follows the settings.
Oh, and I changed a few array_key_exists to isset which is faster.
Comment | File | Size | Author |
---|---|---|---|
#23 | menu_front_5.patch | 4.42 KB | Richard Archer |
#22 | menu_front_4.patch | 4.26 KB | Richard Archer |
#20 | menu_front_3.patch | 4.13 KB | Richard Archer |
#18 | menu_front_2.patch | 3.61 KB | Richard Archer |
#16 | menu_front_1.patch | 3 KB | Richard Archer |
Comments
Comment #1
chx CreditAttribution: chx commentedThe other system patch got mixed in this one.
Comment #2
drewish CreditAttribution: drewish commentedI was pretty stoked when I figured out that I could create a home link using './' ... This seems like a better way to do it.
Comment #3
chx CreditAttribution: chx commentedA Drupal path which ends in slash is an ugly hack. My solution is clean and rhymes with block settings. So much that I nicked the help text from there.
Comment #4
Dries CreditAttribution: Dries commentedSo what exactly does this do? And why? Why can't I leave the link empty?
Comment #5
webchick> So what exactly does this do? And why? Why can't I leave the link empty?
Basically, this is to create a "Home" link as a navigation item. There's no way to do that currently. You can't leave it blank, because "Path" is required, and you can't enter something like / (even drewish's suggestion of ./ didn't work for me either) because it will give you a page not found error (with clean URLs disabled, anyway).
Comment #6
Dries CreditAttribution: Dries commentedMaybe the path shouldn't be required then? Did we try that approach?
Comment #7
Richard Archer CreditAttribution: Richard Archer commentedRight throughout menu.inc are assumptions that items do not have empty paths. Items with a blank path are filtered out of the visible tree and I think introducing this as a feature would generally create havoc.
I'm not very fond of this patch though...
- introducing a special token smells like a hack
- the token contains a word yet cannot be translated.
Maybe if the token was '/' ?
And maybe the performance tweaks and the call to menu_rebuild should be in a separate patch?
Comment #8
chx CreditAttribution: chx commentedThe performance tweaks can be easily extracted to another patch, they are in one hunk.
The call to menu_rebuild is only necessary if you have this <front> patch because the change of frontpage mandates a menu rebuild.
Comment #9
Dries CreditAttribution: Dries commentedThe reason I didn't commit this yet, is exactly that. It has this hackish smell. Like it is 'patch on' rather than 'build in by design'.
Comment #10
Dries CreditAttribution: Dries commentedComment #11
enderai CreditAttribution: enderai commentedFor what it's worth, the token for the front page is also used when specifying on what pages to show a block. (Individual block configuration)
Comment #12
enderai CreditAttribution: enderai commentedsorry, i meant the <front> token is used in block settings.
Comment #13
Richard Archer CreditAttribution: Richard Archer commentedIf I have a site at: http://www.example.com/mysite/ how can I make a home link which points to that URL? (I mean, so the user sees that URL in the status bar when they hover.)
With this patch installed the home link points to http://www.example.com/mysite/?q=node
Comment #14
chx CreditAttribution: chx commentedLOL, Richard are the roles switched? We ask this from the menu maintainer not vica versa :)
Comment #15
Tobias Maier CreditAttribution: Tobias Maier commentedhe's right the frontpage is everytime the same as http://www.example.com/mysite/
and for seo it would be good if this would stay so.
so you dont need to to variable_get('site_frontpage', 'node') it is enough if it would be ''
Comment #16
Richard Archer CreditAttribution: Richard Archer commentedHere's a new version of this patch. It applies cleanly against HEAD.
It now checks for <front> in common.inc instead of menu.inc. This results in the menu item pointing to (for example) http://www.example.com/mysite/ if the path is <front>.
I have also snuck in a fix for http://drupal.org/node/32001 by making the Home breadcrumb link to <front>.
I'm still not convinced about that tag, but at least it behaves as I would expect now.
Comment #17
chx CreditAttribution: chx commentedthis patch now does not need work, what this patch needs is a nice commit :)
Comment #18
Richard Archer CreditAttribution: Richard Archer commentedBoy, patches go stale quickly!
This version also refactors common.inc to remove a couple of duplicate chunks of code, so now the <front> tag only appears once in that file.
Comment #19
Dries CreditAttribution: Dries commentedurl()
is an important function with regard to performance; url is often called 100+ times / page request. If time permits, I'd be interested in some quick benchmark results.Comment #20
Richard Archer CreditAttribution: Richard Archer commentedI set up a test harness omitting the call to drupal_get_path_alias.
The
&& $path != '<front>'
adds 1% to the execution time.The refactoring saves 1%.
So the patch is neutral.
Caching the clean_url variable in a static var yields a further 2% gain. So the attached patch implements this new feature with a modest performance improvement.
There also appears to be a lot of room for optimisation hiding behind the call to drupal_get_path_alias. But I'm not going there :)
Comment #21
Dries CreditAttribution: Dries commentedSorry for nitpicking but:
intval
? We never use that.variable_get()
is quite uncommon. I suggest adding a code comment. It might also be worth documention<front>
?Thanks!
Comment #22
Richard Archer CreditAttribution: Richard Archer commentedI used intval for performance. String comparisons and runtime type conversions are slow. By converting the variable once to a datatype on which it is faster to perform boolean operations we gain every time url is called.
In this version I have replaced the intval call with a more Drupal-like structure. And added some comments.
I am still not a fan of the <front> tag. But I have looked at allowing empty paths and it is not trivial to do so. The empty path is used as a termination condition on various loops that parse path segments. I'm sure menu could be converted to behave as expected with empty paths but I question the value of these changes.
Besides... is an empty path any more intuitive than <front>?
Comment #23
Richard Archer CreditAttribution: Richard Archer commentedrerolled
Comment #24
Crell CreditAttribution: Crell commentedWell, may not be immediately intuitive, but that's what the description text is for. The same flag is also used by the blocks module and the contrib sections.module, so it's at least consistent system-wide, which is perhaps more important than the tag itself being perfectly selected.
+1 on this.
Comment #25
Dries CreditAttribution: Dries commentedI committed this patch because it fixes an annoying problem. Thanks!
I still think we should try to use the empty path instead. As such, I'm making this an 'active task' with normal priority.
Comment #26
Richard Archer CreditAttribution: Richard Archer commentedComment #27
Richard Archer CreditAttribution: Richard Archer commentedComment #28
WeRockYourWeb.com CreditAttribution: WeRockYourWeb.com commentedIn my installation I simply create a "home" menu item that links to index.php. But I'm assuming index.php is not everyone's home page?
Cheers,
Alex
Comment #29
WeRockYourWeb.com CreditAttribution: WeRockYourWeb.com commentedI forgot to mention that I set "index.php" as my "default fron page" under admin -> settings -> default front page.
Cheers,
Alex
Comment #30
coofercat CreditAttribution: coofercat commentedI see a whole lot of code being written, but I found a (non intuitive!) solution using Drupal 4.6.6.
1) Create a page (in my case this is node/1)
2) Create a menu item (mine is called "Home Page" and links to node/1)
3) Create a URL Alias from "node/1" to "/" (or wherever your home page is)
With this, it seems Drupal converts the link it would have had to node/1 with "/", which is what we were originally after. The browser then requests that, and Drupal returns whatever the home page contains (not necessarily the contents of node/1).
This isn't exactly 'nebie friendly' and requires nice URLs to be switched on, but it works. It might save someone an hour or two tinkering time!