Add a Drupal menu item with a hard coded path to a view that accepts arguments? - drupal

I have a view page that accepts a taxonomy term id as an argument at /foo/%bar. I want to add several menu items to the primary links in the form of /foo/actual-bar.
Whenever I try to do this I get the error message "The path '/foo/actual-bar' is either invalid or you do not have access to it."
How can I add such menu items?
Thanks,
Finbarr

Off the top of my head I believe there are a couple ways to do this:
Use absolute URLs (http://yoursite.com/foo/actual-bar) in the menu, which should bypass the check.
Define the links in a custom module using hook_menu()
It does seem to me that there should be a better way to achieve this, but these two options should at least get your going in the short term.

Another way would be to set the url in the view to foo/% it makes the argument required and the 6.x menu system will then see it as a valid URL.
However, just /foo will no longer be a valid URL, so you may need to create another page display in the view to accommodate the URL with no argument.

i recommend set path in such way: /foo/%/bar
so you can access it via: /foo/actual/bar

Oddly, I have a custom module that defines a hook_menu but the menu UI won't allow me to enter it into the system.
Had to do the absolute path solution... though I sure don't like it!

Related

Am I able to create a taxonomy/term/%/x view path using the term alias?

I have enabled the built in taxonomy/term/% view
I have created a display with path /taxonomy/term/%/test
I also have a URL alias setup on the taxonomy/term path to be /fruits/apple
So I would expect this to work /fruits/apple/test would display my view.
When I browse to this path I get Page not found.
If I browse to the un-aliased path ie /taxonomy/term/156/test it works.
Should the alias work like this?
Ive tried every combination I can think of. Reenabled the view, created new displays, removed all other displays etc
Try this: Path redirect. If itsn't help, rewrite engine help to you.
Try sub-pathauto module.
This module extends that behavior by also matching known sub-paths and
replacing them with their respective alias.
For example, if user/1 is aliased to users/admin, this module rewrites
the link to the user contact page user/1/contact to use the aliased
URL users/admin/contact instead.

redirect to a page is not working properly in asp .net which is inside sub folder

I have sub folders says X,Y,Z. I'm making menu list dynamically using 'ul', 'li' tags based on user rights. Inside 'li' tag i have 'a href="#"' tag. The tag 'a' filled from database dynamically.
The problem is the tag 'a' has link X/home.aspx. When i click first time this works since it is available. second time 404 page not found error arising. The link become X/X/home.aspx. Obviously this structure is not available. So, how to redirect.
Thanks
I don't know exactly how your href is continually being added to in this specific scenario (it's a bit of a pitfall in a number of areas, sometimes when using custom controls, etc.), however, you should qualify all of your links from the root by using a prefixed forward-slash (/, i.e. /x/home.aspx).
But we're not done, ASP.NET can transform these too, in other scenarios, so you might want to use the tilde+forward-slash prefix (~/, i.e. ~/x/home.aspx); this indicates the root of the virtual directory where the site is housed.
In this way, regardless of which level of the sites directories you are in, the links always refer to a full path, so to speak.
Your hrefs are relative from the page not from the root of your site...
So do not use "x/home" but use "/x/home".. or use "~/x/home"
Probably you are appending the directory.
If you click for 3rd time you get X/X/X/home.aspx?
Post your code in order to get more help.
Use Page.ResolveUrl
Page.ResolveUrl("~/x/home.aspx")

Filter by third argument in Drupal Views

I am trying to create a Block View filtering by the path's (actually an alias) third argument, but can't succeed.
The path where the block is displayed is sitename.com/first/second/third.
Actually the third argument is the node's author, in the end, I am trying to display a block where only the content created be the author of the node the block is in...
I.e: in the content type Garage node created by user Joe, there should be a block of content type Cars created by Joe. The node's path would then be garagecars.com/garages/spain/joe.
I have tried setting 3 Global:Null arguments and then User:Uid but it doesn't work.
Help? Any other way to filter by node author? (have been a long while searching and the "filter by path arguments" approach seemed the good one, but I must be missing something then).
UPDATE: in the Views preview the path garages/spain/joe works but it doesn't in the page itself http://garagecars.com/garages/spain/joe... which has me ever more puzzled.
SOLVED: I was inserting the blog programatically throught the views_embed_view($viewName, $display_id, $args)... that's why it DID work on preview but when the page was rendered, the arguments set programmatically overrode the one's in the path, thus not working.
Solved in the same question. Information provided on making this work.

Menu path in Pathauto

How do I get pathauto under Drupal 7 to generate a URL alias by the full menu path?
Just an update in case anyone comes across this with a more recent version of Pathauto/Token. This worked for me:
[node:menu-link:parents:join-path]/[node:menu-link]
I ended up using:
[node:menu-link:parent:url:path]/[node:menu-link]
Heavy caution though: If the node does not have a menu link, you'll end up without an automatically aliased page. On the bright side, this might make you aware of orphan pages. (Consider it a feature!)
Note that using the pattern:
[node:menu-link:url:path]/[node:menu-link]
will only give the node's menu link, not that of the parent (which would be needed to reference the parent's path).
Or the pattern:
[node:parent:url:path]/[node:menu-link]
throws an error in my instance of Drupal 7 about invalid tokens (even though I have the token module installed).
[node:menu-link:parent:url:path]/[node:title]
If the node is not in the menu, then it does not create an alias. Otherwise this seems to work for n-tier menus.
I think it has to be this pattern now:
[node:menu-link:url:path]/[node:menu-link]
"path" instead of "alias"
You'll need to install the contrib Token module as well -- although a lot of the features of Token are part of core in D7, some of the edge case tokens (like the full menu path of a given node) aren't provided by core automatically.
With that installed, I believe that [node:menu-link:parent] or [node:menu-link:parent:url] should work.
The pattern that works for me is the following:
[node:menu-link:parent:url:alias]/[node:menu-link]
I also intalled the Token module like Eaten suggested. Don't know if [node:menu-link:parent:url:alias] is part of core or lives in contrib.
If you're attempting to make aliases for pages that are 3rd level or deeper, for example:
Home page
> Level 1 page
> Level 2 page
> Level 3 page
and you want the alias for Level 3 page to look like http://domain.com/level-1/level-2/level-3, I got it to work for me by setting my pattern to:
[node:menu-link:parent:parent:parent:title]/[node:menu-link:parent:parent:title]/[node:menu-link:parent:title]/[node:title]
Notice that I added :parent to the token, and for the first one I added it twice.
Enjoy!
[node:menu-link:parents:join-path]/[node:title].html
This is the solution I use:
[node:menu-link:parents:join:/]/[node:menu-link]
It will separate parent menu items with a dash. That is what I need.
For anyone who stumbles upon this answer, and wonders how to add this:
Configuration > Search and Metadata > URL aliases, then create under "Patterns" tab.

Drupal views add form to add record

I have some view which lists my module table entries.
What is the most elegant way to attach a form below the view to add record?
Waht I am trying to do know is:
I created dedicated form in my module:
function my_module_form_add_record($form_state) {
form fields.....
}
I added to the view theme file:
$add_form = drupal_get_form('my_module_form_add_record');
print $add_form;
But I do not like this solution for at least 2 reasons:
I does not work ...
2. Even if it worked - it is depended on the theme file! So if I change the theme - functionality is crashed.
I would like to find more elegant solution to attach form from custom module to the view.
I know of the existence of the "Views Attach" module but it has no option of adding custom forms.
I know also of the existence of the Views Embedded form (and I am usig it) but it is only useful if you want to add form to the every row.
Seems the must be some solution to add record from the view page!
Thanks you for help.
you could use hook_views_pre_render:
This hook is called right before the render process. The query has been executed, and the pre_render() phase has already happened for handlers, so all data should be available.
Adding output to the view can be accomplished by placing text on $view->attachment_before and $view->attachment_after. Altering the content can be achieved by editing the items of $view->result.

Resources