4

I'm using pathauto to username paths (/member/[username]). After changing a username the url alias doesn't change and the user edit page doesn't have an option to change it manually.

Is it possible to change it with a rule?

1
  • On the off-chance that you're doing some extra sanitisation on the username I'm not sure if rules will be able to handle it without a bit of custom code
    – Clive
    Jan 3, 2013 at 18:28

1 Answer 1

6

Yes, you should be able to do this with a rule. Something like the following:

  1. Event: 'After updating an existing user account'
  2. Conditions: 'Data comparison'. Compare account-unchanged:name to account:name and make sure you negate, so the rule is fired when they don't match (i.e. when this field has been updated)
  3. Actions: 'Create or delete any URL alias'. THis should be under the 'Path' section. Select account:url and create a new value for it

Hope this helps!

Rules export:

{ "rules_change_user_url_alias" : {
    "LABEL" : "Change user URL alias",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "path" ],
    "ON" : [ "user_update" ],
    "IF" : [
      { "NOT data_is" : { "data" : [ "account-unchanged:name" ], "value" : [ "account:name" ] } }
    ],
    "DO" : [
      { "path_alias" : { "source" : "user\/[account:uid]", "alias" : "member\/[account:name]" } }
    ]
  }
}
3
  • 3
    Beat me by a few seconds there ;) Hope you don't mind I added in the rules export
    – Clive
    Jan 3, 2013 at 18:24
  • 1
    Wonderful! Now the answer's even better. Jan 3, 2013 at 18:25
  • 2
    I also want to add that you may want to use the 'Create or delete any URL alias' action twice. Once to delete existing aliases and once to create the new one... just an option! Jan 3, 2013 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.