OK, so I want to link a menu item to a file, but I don't want to do a full path because I'm changing the full path eventually from development to production. I've researched this (and in the past done some things—some things I'm not proud of...) and I see lots of hacks and what-not, but that all makes it seem to me like I'm not getting it
Let's say I want to create a menu that links to a file. Well, I know there's a sites/default/files directory, so for the file link I put in this:
sites/default/files/jackson_logo.png
This gets me back a don't-have-access-error.
This is odd, to me, since this very link will (does!) work if I put it in the theme menu.
Which I guess tells me themes have permissions that menus don't, or something. I've tried a lot of proxies as well, setting up another directory, etc.
I get the concept that drupal wants full links to things that are not part of it, but not why I can't make the file enough a part of it that I can link it directly.
Straighten me out, folks.
Comments
A quick look into menu
A quick look into menu module's code tell us you re not allowed to add a local link that is not in the router. That leads to two obvious ways to quickly deal with it without hacking the code:
1. Manually adding the image url to your menu_router table;
OR
2. Adding the menu item in a module with hook_menu.
I've just tested the 1 and I do the 2 all the time.
Hills Web
PHP or MySQL?
Appreciate the info.
I still feel like I'm not getting it. Not that I can't do it, but I'm not grasping the philosophy. It seems like a menu item linking a file is a foreign concept somehow.
I guess what I expected was something like:
1. Upload a file. That creates a node.
2. Create a menu item. Link it to the node created in step 1.
It seems like files aren't first-class citizens in Drupal?
Try
Try http://drupal.org/project/attachment_links
Didn't work for me
but I found this:
over here: http://drupal.stackexchange.com/questions/2203/how-do-i-create-relative-...
I just made a custom module with the above function, *enabled it*, and I could suddenly link directly to my PDFs. Hope this helps someone else!
I tried this and it did allow
I tried this and it did allow me to create a menu link to a file, but then that link doesn't show in my menu or the admin page even though I can see it in the database and everything appears to be correct.
Sean Robertson | @seanr1978 on twitter
seanr@webolutionary.com
For multilingual
@sveldkamp thanks for your solution. I tried it but in multilingual I got the language prefix so I had to add a token in the module together with your code :)
I hope someone can use it.
//trying to answer one question for each one that i make.
//this way, drupal will be more friendly and strong
Thanks!
This worked like a charm, sveldkamp!
Thank you!
My custom module for this
I am using Drupal 7 and I want my content editor to be able to add a menulink to any file that resides in the folder 'downloads' (in the root). I solved this by creating a custom module for this. The first part of my module I got from this thread. I did not find the solution above with token very clean nor was it working so I used a custom page callback function that executes a drupal goto with an absolute path (this is because on multilingual sites drupal adds the language prefix and otherwise you would have a false link to /en/downloads/xxx instead of /downloads/xxx).
Here is the code of my custom_module: