I'm looking for a suggestion to update the path alias during user registration. I've hidden the name field and have given it a value of an md5(microtime()) and during the insert operation change it using SQL UPDATE to a name based on the email address and the uid. The problem with this method is pathauto has already set the path for the user name. Suggestions?
Comments
Comment #1
gregglesI'm changing the title to reflect what I think you want.
Is that a more true statement?
Your goal is to have a path alias textbox on the user register/create/edit form similarly to how it is provided for nodes, right?
Comment #2
Anonymous (not verified) commentedNo, that isn't it and doesn't make sense. I'm programmatically changing the name field to hidden and populating it with random data and then updating it during the insert operation to a name based on the email address. The problem is that the alias is set before I get the name changed. Other than doing an update of the path table is there something else that could be done.
Comment #3
Freso commentedHm. Isn't this a question of using an [email] Token or something instead of the [name] (or whatever it currently is :)) token? If there isn't one currently, perhaps this is really a feature request for Token to add one?
Alternatively, perhaps populating the name field with the value from the e-mail one, instead of a random one, could be a viable work-around? One of the sites I'm working on is doing that, using the additional e-mail field as a "did you write the e-mail correctly?" check and then checking if name and mail are the same on form validation.
Comment #4
Anonymous (not verified) commented@fresco: No token is possible. This is the registration form that I have altered. I'm hoping for a method to call to reset the alias. If not, I'll create my own.
Comment #5
gregglesOh, ok.
The Pathauto module is designed to run with a weight of 1 which means that anything your module does to change data around should be able to run with a weight of 0 or -1 and be able to happen before Pathauto which would make the code that Pathauto runs "just work". There is a chance that the data is being cached - however the call to token_get_values in pathauto.inc clears the token cache.
Now, since you seem intent on doing this yourself rather than making the tokens work properly, I suggest you disable Pathauto for users so it doesn't create aliases and then call path_set_alias directly - http://api.drupal.org/api/function/path_set_alias/5 Pathauto is a convenience wrapper around the core path functions.
Also, re #4 - His nick is Freso, not fresco.
Comment #6
Anonymous (not verified) commentedI'm thinking the array_merge of the $user data and the $edit array in the pathauto_user function is an bug. The token array tokens and values seem to be silly. They are mixed between the Anonymous user and the registration data in one instance of the call and the authenticated user and no $edit data in a subsequent call. It makes the tokens not reliable to give a correct alias. The [user-name] is Anonymous for the first instance and so the alias becomes user/anonymous. The [user-raw] contains the entered name for the first instance so the alias is correct but no $edit data is in the second instance and the alias becomes user/anonymous. I'll see if I can come up with a patch.
Comment #7
Anonymous (not verified) commentedComment #8
kenorb commentedProbably this issue is related to:
#254422: Using old data for tokens
#383428: Link to user homepage contain a password
So make sure that you've updated $edit array with your user replacement (apart of update sql) (Example: $edit['name'] = 'some_name')
And make sure that your weight of module is before pathauto. Because pathauto gets username from object which is passed via hook_user during creation, not directly from database.
Comment #9
kenorb commentedIf it will not solve your problem, please re-open it.