11

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?

  • 2
    Save yourself the headache and just use pathauto. This problem has already been solved, why resolve it? Pathauto only causes a performance hit when you are saving nodes (and even then, only minimal). – Matthew Scharley Mar 20 '11 at 11:37
  • 4
    Because one can generate nicer urls than pathauto and if all you need is to generate urls for one or two types, you can get rid of two modules by implementing a single hook. Also, Bulk import is quite slow (and even broke at some point personally, it simply refuse to import anything after 400 nodes), whereas my lightweight cron/bulk script managed to import 500 nodes per second, which is quite nice when you have 100k nodes to generate aliases for. – wildpeaks Mar 20 '11 at 15:20
12
/**
 * 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()

1

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.

  • See what reported in hook_insert(), which contains the following sentence: "This hook is invoked only on the module that defines the node's content type (use hook_node_insert() to act on all node insertions)." – kiamlaluno Mar 20 '11 at 12:56

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.