1

I am setting an alias programatically, using path_set_alias() in Drupal6.

Looking at the code of path_set_alias in path.module, I see that if I pass the pid (path id), the old alias(s) for that node will get deleted, which is what I want.

When I load the node, though, I see no pid property set on the node, but the record for the node's alias exists in url_alias table.

Why doesn't pid exist on the node object? Must I retrieve the pid from the url_alias table and then pass that in to path_set_alias to remove the old alias?

2 Answers 2

1

It looks like a bug, see http://drupal.org/node/633916

It's optional to path the pid to path_set_alias() so it should work without passing it.

2
  • It's optional, but if you don't pass it, it won't delete the old alias. See the code for path_set_alias.
    – Aaron
    May 17, 2011 at 19:51
  • @Aaron I checked the code I'm pretty sure it works fine without pid, because it looks up the old path and make an UPDATE: else if ($path && $alias) { // Check for existing aliases. if ($alias == drupal_get_path_alias($path, $language)) { // There is already such an alias, neutral or in this language. // Update the alias based on alias; setting the language if not yet done. db_query("UPDATE {url_alias} SET src = '%s', dst = '%s', language = '%s' WHERE dst = '%s'", $path, $alias, $language, $alias); }
    – tostinni
    May 17, 2011 at 21:11
0

As you can see in path_nodeapi(), path.module only loads the alias and adds it to the node object, not the pid.

In fact, it is doing it wrong anyway (it is supposed to return new data, not add it to $node) since that won't work in PHP 4. Not that anyone on this world should still use that, but Drupal 6 still officially supports it.

Also, there is no page_node_load() function in Drupal 7, so this part has been removed completely there, possibily for performance reasons (No need to load the alias if no link for this node is displayed anywhere and since it's not used anyway when a link is generated, it is mostly useless).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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