Adding a custom path for node I have enabled the path auto and workbench modules in my drupal installation. I have to set the url alias once only. Once a node is published and url alias is generated, the url alias should not be generated again if end user changes the title of the node. Also I have to generate the url alias only when node goes to published state.

I am trying something like this:

function hook_entity_presave($entity, $type) {
  //Do not create url alias of node unless its not published and if you create a Draft of a published node, the URL of the published node should not go away.
  if($entity-&gt;workbench_moderation['current']-&gt;state != 'published'  &amp;&amp; !isset($entity-&gt;workbench_moderation['published']))
  {
    $entity-&gt;path['alias'] = '';
    $entity-&gt;path['old_alias'] = '';
    $entity-&gt;path['pathauto'] = 0;
  }
  else {
    $entity-&gt;path['pathauto'] = 1;
  }
  // if node is published, do not change the url alias if end user changes the title of the node. 
  if(isset($entity-&gt;workbench_moderation['published'])) {
    $entity-&gt;path['alias'] = $entity-&gt;path['original']['alias'];
  } 
}


and I am trying to accomplish this with hook

function hook_node_presave($node) {
  $node-&gt;path['alias'] = $node-&gt;path['original']['alias'];
  $node-&gt;path['pathauto'] = 0;
}
You can set that in the URL aliases configuration. 

In http://example.com/admin/config/search/path/settings

In the section 'update action', check one of the two:

Do nothing. Leave the old alias intact.
Create a new alias. Leave the existing alias functioning. 


The default is:

Create a new alias. Delete the old alias.