By storbaek on
I see on drupal.org that a discussion happened a year ago, but I cannot see if it resulted in anything.
Use case: You have a parent and the child gets the url: www.yourhomepage/parent/child
The problem is if you have several parents. A config option where you could choose parent would solve this.
Does anyone know if this works?
Comments
Hook?
As far as I remember, there is a hook_pathauto() function that generates these patterns (like [bookpath] and [catpath], which from context I take to be similar to what you're describing).
So if relativity were to implement relativity_pathauto(), it would be possible to extend the existing patterns with this.
Also, [catpath] chooses the vocabulary with the lowest weight. Perhaps relativity could do something similar in the case of multiple parents...
How to create relativity_pathauto()?
There is a hook_pathauto(), but how can this be used to implement relativity_pathauto()? It sounds interessting and it would probably solve the problem! Is it easy to do?
I ended up using the new
I ended up using the new token module and the new pathauto module after listening to a lullabot podacast. Jeff Eaton explained some of the concepts of token and pathauto. I have to thank the guys at lullabot and highly recommend the lullabot drupal podcast (just in case there is anybody who doesnt know :-) )
I "hacked" the token module to output the ancestor nodes as tokens.
Then you can use those tokens very easily for pathauto and also with the "custom breadcrumbs" module.
So for a given node in a tree like hirachy like:
the output will be:
path: level-1/next-level/my-node
breadcrumb: Level 1 » Next level » My Node
This is a working approach. If somebody is interested in how i did it will dig in my sandbox to find and post my amateur style code snippet. Maybe somebody has an idea how to do this "the right way". But the positive message is: its possible and it works :)
I guess it would be easy for a "real coder" to add token generation to node relativity.
----------------------
okay.cool
I hope somebody can use or
I hope somebody can use or even give me some feedback on this code in order to improve it:
The important thing is to use the dev version of pathauto and the token module i guess.
i changed the file token_node.inc in the token module folder, i guess instead you also could or maybe should override the function in the template.php
i changed 2 functions:
Its everything but clean, but it works. Any suggestions?
----------------------
okay.cool
Need clarification on pathauto settings
Hi Jochen
Thanks for your explanation. Your code is what I im looking for, so of course, I had to try it!
I have changed the two functions based on the code you have submitted above, but it does not work. It might be because of a missing pathauto setting. I have tried with blank (not entering anything under the content type in pathauto) and a number of of settings.
Example: Using [parent]/[title] when adding a child called nicecode, would give me a title of
/?q=%5Bparent%5D/nicecode. As you can read from this, I'm not using clean URL's, but I don't assume that this should be a problem. The /[title] is also being printed correctly.
I have also tested the following, but these did not work either:
[relpath]/[title]
[parent_title]/[title]
[ancestor1_title]/[title]
[ancestor1]/[title]
It might be a pathauto settings problem or a code problem. I'm not sure how I can test if it's a code or a path auto problem.
Any ideas?
are you suing the new dev
are you using the new dev versions of the 2 modules???
pathauto: http://drupal.org/node/129349
token: http://drupal.org/node/143907
----------------------
okay.cool
[relpath]/[title] create blank parents
I followed your previos post, by downloading the dev versions and adding them. I had an error when updated the pathauto, which I now see, did not update the pathauto to the dev version. I then disabled the two modules, removed them, added the dev versions and enabled them. I now have this:
Pathauto: 5.x-2.x-dev
Token: 5.x-1.x-dev
I changed the two functions again, but it still does not work with the parent. My pathauto settings are these:
Default path pattern: [title]
Pattern for parent: [title]
Pattern for children: Should I use [relpath]/[title]? I did notice one change from before. Using only gives me [relpath]/[title] now gives me /nicecode with your code and not /?q=%5Brelpath%5D/nicecode. I have tested deleting [title] in Default path and Parent path, but I still get /nicecode.
Using [relpath]/[title] therefore gives me blank parents...
Any suggestions?
hmmm... go to blocks and
hmmm... go to blocks and enable the "Node relativity: ancestors".
Does it show you some ancestors? The funtion i used is the same that gernerates the ancestors in that block.
----------------------
okay.cool
The ancestors are showing
The child ancestors (the parent) is already being shown as a block correctly. It's shown in my sideblock and I have configured the block to show both for parent and child content types. It look ok, but the title is not taken from the anscestor.
But I would like to know what are your pathauto settings?
Thanks for your input so far! It's really frustrating not to have this working.
My pathauto settings are
My pathauto settings are [relpath]/[title]
the rest of my code is only for custom breadcrumbs.
You wrote "but the title is not taken from the anscestor". My question is: the title is not showing in your ancestor block?
----------------------
okay.cool
Anscestors seem ok!
Hi derjochenmeyer
Thanks for your input and willingsness - I appreciate it!
To answer your question, I have added the anscestor block and it show the parent to the child correctly. So the block seems to be working just fine.
But adding [relpath]/[title] only gives me the [title]. [relpath] is for some reason blank. If I have a parent called father and I add a child called daughter, it only gives me /daugther, while it should have been /father/daugther.
[relpath]/[title] surely does something (insert blank that is), because inserting something else will give me a value before /daughter.
Any ideas?
im sorry that my solution
im sorry that my solution does not work for you. One idea that i have is: maybe you need to set the parent-chlid relationships to "one". Did that help?
----------------------
okay.cool
Ready for test
I requested the feature in node relativity and it has now been developed and ready for test in 2.x :-)