0

I have a content type using the following pathauto-token pattern: [node:menupath]/[node:title], I added manually a menu using a hook_node_insert (see my previous question: creating a menu in a hook_node_insert()).

When the node is saved it doesn't have the [node:menupath] token in the URL, just the [node:title]. I decided to generate the path using pathauto API and this code:

$options = array(
  'language' => isset($node->language) ? $node->language : LANGUAGE_NONE,
);
module_load_include('inc', 'pathauto');
$uri = entity_uri('node', $node);
$path = pathauto_create_alias('node', 'insert', $uri['path'], 
  array('node' => $node), $node->type, $options['language']);

Doing this lead to duplicates in the url_alias table, the [node:menupath]/[node:title] alias being created first then the title.

I tried to add a $node->pathauto_perform_alias = FALSE; in a presave, but seems to be inefective.

Also I tried to set my new path in the hook_node_insert but had no success:

$path = pathauto_create_alias('node', 'insert', //...
$node->path = $path;

My code doesn't feel right, what would be the normal way to avoid duplicate and getting my pattern to work ?

Thanks

0

I finally moved the insertion of my menu in hook_node_presave() and then pathauto worked normally.

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.