Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The documentation for the user_mail_tokens() function reads:
/**
* Return an array of token to value mappings for user e-mail messages.
*
* @param $account
* The user object of the account being notified. Must contain at
* least the fields 'uid', 'name', and 'mail'.
* @param $language
* Language object to generate the tokens with.
* @return
* Array of mappings from token names to values (for use with strtr()).
*/
However, user_mail_tokens unconditionally calls user_pass_reset_url() which assumes the existence of 'pass' and 'login' fields, in order to set the '!login_url' token.
I can think of at least three possible fixes for this inconsistency:
- Revise the documentation to note the additional requirements of the 'pass' and 'login' fields.
- Set the '!login_url' token to url('user/login') if the 'pass' and 'login' fields are not supplied.
- Call user_load() if the 'pass' and 'login' fields are not supplied.
Three trivial patches attached; pick one.
Comments
Comment #1
pillarsdotnet CreditAttribution: pillarsdotnet commentedThis is a d6-only bug, because the documentation has been completely removed in d7. Perhaps the documentation should be likewise removed in d6?
Comment #3
pillarsdotnet CreditAttribution: pillarsdotnet commented(sigh)
Re-rolled all three for current d6 checkout.
Comment #4
pillarsdotnet CreditAttribution: pillarsdotnet commentedA fourth possibility is to simply remove the documentation altogether, as it exists in d7/d8.
Comment #5
jhodgdonComment #4 - NO. We should instead document the function properly in D7/8. Our doc standards require @param and @return doc for all functions.
Original issue suggestions numbered 2 & 3 - these would be API functionality changes to Drupal 6, which at this point should be avoided.
So that leaves suggestion #1 - fix the doc.... You need to make patches without the -D6 extension so they can get tested (see help text below the attach field). But that aside, the first patch in comment #3 looks fine to me. I changed the name and re-uploaded it so it can be tested; provisionally setting to RTBC since it should be fine.
Comment #6
jhodgdonComment #7
pillarsdotnet CreditAttribution: pillarsdotnet commentedRelated d7/d8 issue: #1166388: Regression: user_mail_tokens() rewritten by #554088 needs docs.
Comment #8
pillarsdotnet CreditAttribution: pillarsdotnet commented#5: user_mail_tokens-fix_documentation-401266.patch queued for re-testing.
Comment #9
Gábor HojtsyThanks, committed.