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

cburschka’s picture

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...

storbaek’s picture

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?

derjochenmeyer’s picture

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:

  • Level 1
    • Next level
      • My Node

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

derjochenmeyer’s picture

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:

  • in function node_token_values($type, $object = NULL) i changed the beginning to
    <?php
    function node_token_values($type, $object = NULL) {
      switch ($type) {
        case 'node':
          $node = $object;
    
    	  if (module_exists('relativity')) {
    	  
    					  $my_ancestors = relativity_load_ancestors($node, $load_multi_parent=1,  $block=FALSE);
    				
    					  if (is_array($my_ancestors)) {
    				    	  foreach($my_ancestors as $recent_node)
    				          {
    						        $my_path .= str_replace(" ", "-", strtolower(check_plain($recent_node->title)))."/";
    								$my_titles[] = $recent_node->title;
    								$my_urls[] = $my_path;
    						  }
    					  }
    						
    				      $values['relpath'] 		= $my_path;
    					  
    					  if ($my_titles[0]) { 
    					  	$values['parent_title'] 		= $my_titles[0]; 
    					  	$values['parent'] 			= $my_urls[0];
    					  }
    					  
    					  if ($my_titles[1]) { 
    					  	$values['ancestor1_title'] 		= $my_titles[1]; 
    					  	$values['ancestor1'] 			= $my_urls[1]; 
    					  }
    					  
    					  if ($my_titles[2]) { 
    					  	$values['ancestor2_title'] 		= $my_titles[2]; 
    					  	$values['ancestor2'] 			= $my_urls[2]; 
    					  }
    					  
    					  if ($my_titles[3]) { 
    					  	$values['ancestor3_title'] 		= $my_titles[3]; 
    					  	$values['ancestor3'] 			= $my_urls[3]; 
    					  }
    					  
    					  if ($my_titles[4]) { 
    					  	$values['ancestor4_title'] 		= $my_titles[4]; 
    					  	$values['ancestor4'] 			= $my_urls[4]; 
    					  }
    
    	  }
    
          $values['nid']            = $node->nid;
    [...]
    ?>
    
  • and in function node_token_list($type = 'all') {
    <?php
    function node_token_list($type = 'all') {
      if ($type == 'node' || $type == 'all') {
    
      
    	  if (module_exists('relativity')) {
    	  			
    		$tokens['node']['relpath'] = t('The Ancestor Path.');
    					  
    		$tokens['node']['parent_title'] 		= t('Parent title.');
    		$tokens['node']['parent'] 				= t('Parent path.');
    
    		$tokens['node']['ancestor1_title'] 		= t('Ancestor1 title.');
    		$tokens['node']['ancestor1'] 			= t('Ancestor1 path.');
    		
    		$tokens['node']['ancestor2_title'] 		= t('Ancestor2 title.');
    		$tokens['node']['ancestor2'] 			= t('Ancestor2 path.');
    		
    		$tokens['node']['ancestor3_title'] 		= t('Ancestor3 title.');
    		$tokens['node']['ancestor3'] 			= t('Ancestor3 path.');
    		
    		$tokens['node']['ancestor4_title'] 		= t('Ancestor4 title.');
    		$tokens['node']['ancestor4'] 			= t('Ancestor4 path.');
    
    
    	  }  
     
    
        $tokens['node']['nid']            = t('Node ID');
    [...]
    ?>
    

Its everything but clean, but it works. Any suggestions?

----------------------
okay.cool

storbaek’s picture

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?

derjochenmeyer’s picture

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

storbaek’s picture

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?

derjochenmeyer’s picture

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

storbaek’s picture

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.

derjochenmeyer’s picture

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

storbaek’s picture

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?

derjochenmeyer’s picture

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

storbaek’s picture

I requested the feature in node relativity and it has now been developed and ready for test in 2.x :-)