1

Does anybody know where/how to change the pathauto-URL of a node (that comes out of the db table "url_alias")?

Background (Example):

I have a page with list of nodes (A, B, C)

A -> links to "clean-URL/A.html" B -> links to "clean-URL/B.html" C -> should not link to "clean-URL/C.html" but to "clean-URL/A.html" (C has a field that says it should link to A)

So, I want that everywhere there is a link to C, the link should be changed to A. For example in search results or in views.

Unfortunately I can't find a pathauto hook that does something like "render_pathauto_link_of_node"...

1

I found what I needed. It is the function hook_url_outbound_alter...

function myModule_crawler_url_outbound_alter(&$path, &$options = FALSE, $original_path){
    $mother_nid = $options['entity']->field_mother_series_nid["und"][0]["value"];
        if( $mother_nid > 0 ){
            $path = "CLEAN-URL/".$mother_nid;
            $options['alias'] = "CLEAN-URL/".$mother_nid;
        }
}

Thanks for helping!!!

0

I'm not really sure exactly you are trying to ask here, but if you use drupal's l() function, it will return a link utilizing the aliases, eg:

$foo=l('Click here to goto bar','node/' . $nid);

will create a link using the url alias of the node in question (assuming of course that $nid contains an actual node id).

You could use this in custom PHP code or in a PHP field in Views, but, I am also thinking you could use Views' field rewriting along with tokens to accomplish this as well if it is based upon a reference field inside another node as well that is included (and then hidden) in the View's fields.

ADDITION based upon commentary:

You could take a dull ax to this and do something along these lines in hook_init()...

function YOURMODULE_init() {

  $mgo=menu_get_object();

  if (!empty($mgo-> /* whatever field you are talking about in your content */ )) {

    $nid= /* get the node id from that field */ ;
    if ($nid && $nid!=$mgo->nid) { 
      drupal_goto('node/' . $nid);
    }

  }

  // any other init stuff from your module goes here

}

...which would do the redirect upon page load so your users might see their browser address bar change quickly at the beginning but would end up at the right place.

Also realize you'd never be able to edit the node again without further logic added into the above :)

  • The l() function could be a solution. But, then I have to use it everywhere a link is rendered (e.g. in Views or in search results). Better would be a more centralized solution where the url (the way i want it) is coming automatically from the backend. – Christoph Dec 12 '13 at 9:25
  • the l() function is pretty much the backend in that it is Drupal's core way of generating links. look into the built in url() function as well. – Jimajamma Dec 12 '13 at 13:17
  • But, if you are asking to have pathauto automatically create an alias for one node that points to the alias of another, that's just not how it works (it adds -# to the end until it finds a unique one) – Jimajamma Dec 12 '13 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.