Hello.
I'm working on one module with self-made nodes involved. I was using pathauto to create path aliases like "nodetype/nodetitle" for every of my nodes for a while. But then I had to create more aliases for every node, like "nodetype/nodetitle/operation". So I decided to remove pathauto and create all those aliases with path_set_alias function.
The task itself is pretty simple: to add aliases at node creation, to modify them at node update and to delete at node removal. So I added a couple of path_set_alias calls at hook_insert - and failed. Aliases at path_set_alias("node/".$nid."/operation",$aliasname) were set fine, but there was no way to set aliases like path_set_alias("node/".$nid,"something/title"). Function just didn't add anything to {url_alias} table.
Eventually I figured to move my path_set_alias calls to hook_nodeapi, something like:
if (($op == 'presave') && ($node->type == 'mytype')) {
$node->path = NULL; //to avoid probable conflict with path_nodeapi
}
if ((($op == 'insert') || ($op == 'update')) && ($node->type == 'mytype')) {
//delete aliases if any
path_set_alias("node/".$node->nid);
path_set_alias("node/".$node->nid."/operation");
//create new aliases
path_set_alias("node/".$node->nid,"mytype/".$alias_name);
path_set_alias("node/".$node->nid."/operation","mytype/".$alias_name."/operation");
}
and it seems to work fine :)
Anyway I don't get why I can't create path alias for node page at hook_insert. It's not really a problem since I figured a workaround above, but I would really like to understand how it works. Any ideas?
Thank you.