Create a clean node edit-URL: a kick start

13 Sep 2011

Joris Snoek - Business Dev
+31 (0)20 - 261 14 99

If you are developing a Drupal websystem, that involves lot's of users that are administering nodes (articles) then maybe it's nice to create a clean 'edit-url'. It's not really neccesary, but gives a nice URL eye candy.

With just a few lines of code you can get started. If you really want to use this concept in a live websystem, you need some additional programming to handle things like deleting and editing of nodes and thus aliases. But here is a kick start, that might give you a nice idea to work it out!

Update 27-03-2010

Via Twitter I got feedback from @martinhrabovcin. He pointed me to this module: Sub-path URL Aliases . That will also do the trick. (I haven't tested it yet). Thanks!

The code

/*
* Implementation of hook_nodeapi
*/
function YOURMODULE_nodeapi(&, ,  = NULL,  = NULL) {
  switch () {
    case 'insert':
      // Sanatize the node title, always have trust issues with your websystem users ;-)
       = check_plain();
      //Set path alias, for when user will edit the node
      path_set_alias('node/'. .'/edit',   .'/edit');
      break;
  }
}

The set up

In this case hook_nodeapi, operator 'insert' and path_set_alias will create the alias for you. Drupal will automaticly pick it up in de 'node edit link'.
But as allready said: this is just for the idea. It's quite a raw piece of kick-start code that needs to be further developed. For example: it doesn't handle duplicate titles / aliases, it doesn't handle special characters in your title, it doesn't handle updating your title and alias.
You can use pathauto module to help taking care of the duplicates and special characters (Install the pathauto module and use instead of ).

Feedback, Questions about aliases or hook_nodeapi() ?

Or maybe you know a nice module that does the trick...
Please hit me on Twitter for all your feedback, and any other issue!

Comments

Nóg meer
kennis nodig?

Check ons ons blog archief >