I'm trying create a page view as a normal menu item and I fail with an error, "Views cannot create normal menu items for paths with a % in them."
My question is why not? Is there something about menu API that prevents this?
I'd like to create normal menu items (not tabs) for paths like "custom/%user_uid_optional/tracker" and "custom/%custom_arg/whatever". The new menu api allows me to define custom_arg_to_arg(), which puts the right value into the path.
If I can't do entirely within views, is the workaround to create a page view for "custom/%custom_arg/whatever" then define the menu item in my module?
(thanks as always for the great work on views, btw)
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | views-wildcards-in-page-path-266347-15.patch | 5.27 KB | Sanjo |
| #14 | views-wildcards-in-normal-menu-items-266347-14.patch | 1.91 KB | Sanjo |
| #3 | views_menu_args.diff | 1.46 KB | Dave Cohen |
| #2 | views_path.diff | 641 bytes | Dave Cohen |
Comments
Comment #1
merlinofchaos commentedThe answer is primarily that I haven't done any research into what it'll take to properly implement *_to_arg for this; at the least it's going to require the argument handler eventually deal with it and determine what a default argument should be.
Patches accepted, I suppose!
Comment #2
Dave Cohen commentedThe attached is not really a patch, I just disabled the check and so far things are working. Haven't tested any edge cases or ways for users to hang themselves.
However, the check is performed when saving the menu option, and not when saving the path. So if you select normal menu item first then edit your path to include a %, you skip the check. At least I think that's what originally happened to me.
Dude, views 2 is insane!
(In a good way)
Comment #3
Dave Cohen commentedThis is closer to a patch. I don't think it will pass inspection but its short, please take a quick look. In this patch I allow the menu to contain a '%' only if there is a corresponding _to_arg function for the wildcard. But the tricky part is that views wants to change the '%my_custom' to '%views_arg'. And once that is done, the menu API will not substitute for the wildcard.
I'm sure there is a reason for the views_arg substitution. What problem does that solve?
Comment #4
merlinofchaos commentedIt allows the argument to do validation.
The appropriate way to do this would be to add a _to_arg and delegate that to the argument handler and put that through the default action handler. If it comes up with an argument, use that.
Comment #5
Dave Cohen commentedProblem is, the _to_arg feature is not as rich as the _load feature, you can't give it additional args. So you can't replace %my_custom with %views_arg then have views_arg_to_arg() call my_custom_to_arg() because by then, views_arg_to_arg() has no way to recall what the original to_arg function was.
Would it be OK for views to skip its validation in the case where a _to_arg function exists? Its the sort of case where you better know what you're doing if you create a path like that.
Comment #6
merlinofchaos commentedI wasn't thinking of passing through to your custom _to_arg; instead, I was thinking of having views argument handlers have a method of defining the argument. The system would then have to be smart enough to make sure that the handlers can respond appropriately.
I'm not sure if this will make it in prior to 2.0 or not.
Comment #7
Dave Cohen commentedBut the whole point is to make use of the _to_arg feature. In my case, my_custom_to_arg() has logic that looks at the group context, detects whether it has nodes of a certain type, and if so, returns the group nid. So the menu item will only appear when browsing nodes in groups which also contain my custom nodes.
The _to_arg thing is a menu API feature that's independent of views. When views replaces %whatever with %views_arg, the _to_arg feature can no longer be used.
FYI, instead of bending views to support this, I'm now trying to add the menu items in my own module. Then, in my page callback, I replicate most of the logic of views_page(). I have to be very careful about argument passing, and I'm taking shortcuts like hardcoding the display_id (to 'default'). Still, this seems to be working well enough for me.
Comment #8
merlinofchaos commentedYea, I can say with certainty that Views is not going to let you use your own custom _to_arg. I'm ok with argument handlers having it.
You should probably set the display_id to something that equates to a page display ('page' or 'page_1' or the like).
Comment #9
Flying Drupalist commentedIs this still a possible feature?
Comment #10
entr3p commentedI'm still wondering if this is possible as well.
subscribe
Comment #11
drumnjo commentedditto, I would like this feature so that I can have a top menu item for 'My Friends' that is generated by Flag Friends module....
Comment #12
merlinofchaos commentedRight now my work around is to use page manager module which has this feature for users:uid arguments, at least. Or create the menu item yourself. Or the 'me' module can do stuff with this too I think.
Comment #13
metabits commentedIs it possible to pass as an argument a taxonomy term to the menu entry?
I mean: I have aview with severals page views:
- One page view takes a content type and listed all of them, this view has a path and a menu entry. No problem with this.
- Then I create a second page view that makes the same but has a term (year) as an argument. If I want all years having a menu entry, I have to make them manually, wich is no very funny when having lots of years as arguments. Therefore I was looking for a solution to pass the argument "year" in my menu entries for that view.
This is repeating for several content types that use the same taxonomy term for years, so I cannot use the taxonomy menu for a specific content type because then I cannot use the year menu entries for the rest of the content types.
Any idea of how to make this of passing the "year" term to the menu entries for all my views of different content types that use that taxonomy?
Thanks!
psc
Comment #14
Sanjo commentedI created a little patch that lets a MENU_NORMAL_ITEM behave like a MENU_LOCAL_TASK (the dynamic path creation part).
So you can use % as wildcard in normal menu items and the _to_arg function will replace them with the path element with the same index.
-- Example --
Settings in your View (Page):
- Normal Menu Item
- Path: example/%/details
- Title: Example Details
Now you browse to the page with the path node/5.
My page will show a normal menu item named 'Example Details' with the generated path 'example/5/details' in the menu you chose.
I use this for views of node-types that have a parent node-type. In my views I have an argument for the node reference.
Like this:
PARENT NODE TYPE
--> CHILD NODE TYPE 1
--> CHILD NODE TYPE 2
--> CHILD NODE TYPE 3
It's my first patch so I hope that it works and is helpful for some of you.
Comment #15
Sanjo commentedI created a patch that allows to use wildcards. You have to write the handlers in your own module (anything_to_arg & anything_load possible).
The good thing is that everything else works as before (views_arg_load is untouched and NO additional data is saved in the DB).
I achieved this by writing a new function 'views_load_args' that could be a replacement for the 'views_arg_load' mechanism. (But doesn't have to)
It gets called in 'views_page' when no additional arguments have been passed. I tested everthing but a custom _load-handler.
Additionally I added a little validation for '% at the end' for tabs when you first select the menu type TAB and then add the '%' to the end of the path.
Please review this patch. Thanks.
Comment #16
Sanjo commentedSee http://drupal.org/node/109153
Comment #17
merlinofchaos commentedThis patch completely breaks argument validation. You remove the views_arg stuff without replacing it, which makes no sense to me.
But to see for yourself, make a view with the path node/%/test and set it to be a tab -- then add a validator, such as node type. Then visit a node that is not of the type validated. The tab will not appear. Then, add your patch and clear the menu cache. Now the tab appears.
Comment #18
yngens commentedsubscribe
Comment #19
sammo commentedsubscribe
Comment #20
sammo commented@merlinofchaos (I think this is the right place to post this) Is there any reason why I shouldn't use the following function, or something like it, in a custom module to provide a default replacement where no value is provided for a wildcard?
I don't think it should conflict with anything in views or any other contrib modules as it is new functionality? I'm trying to show the following MENU_LOCAL_TASKS: press-releases/%/list and press-releases/%/calendar on this page: press-releases, and this is the only way I can get the links to show.
If this idea works ok could this be patched into views.module? Or is this bad idea?
Comment #21
mustanggb commented