Pathauto can do the job easily for all content types, but in my case I only have one content type URL that needs to be customized, and I would prefer to not install Pathauto and Token.
Can anyone advise me how to do?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityPathauto can do the job easily for all content types, but in my case I only have one content type URL that needs to be customized, and I would prefer to not install Pathauto and Token.
Can anyone advise me how to do?
/**
* Implements hook_node_insert()
*/
function mymodule_node_insert($node) {
if ($node->type == 'mytype') {
$node->path['alias'] = 'mytype/' . $node->nid;
}
}
Additionally, you may add this code to hook_node_update()
See p. 149 of Pro Drupal Development, use hook_insert(). When a new node is saved, hook_insert() is called. This is the place to handle any custom processing of the node's content before the node is saved. Also look at p. 152-156 Pro Drupal Development which talks about all of the different hook_node_xxxx() functions.
I think using hook_node_insert() as suggested in the previous answer will result in a hook into ALL node creations which will not address your need to alter a specific content type.
hook_node_insert()
to act on all node insertions)."