Il token "user: one-time-login-url" non viene sostituito da token_replace


7

Sto cercando di inviare e-mail agli utenti manualmente utilizzando l'hook hook_mail_alter. Quanto segue è la mia funzione nella sua interezza:

function custom_module_mail_alter(&$message) {
    $email = '[user:name],

A site administrator at [site:name] has created an account for you. You may now log in by clicking this link or copying and pasting it to your browser:

[user:one-time-login-url]

This link can only be used once to log in and will lead you to a page where you can set your password.

After setting your password, you will be able to log in at [site:login-url] in the future using:

username: [user:name]
password: Your password

--  [site:name] team';

    $account = $message['params']['account'];
    $uid = $account->uid;

    $_user = user_load($uid);

    dpm(token_replace($email, array('user'=>$_user)));
}

L'output è simile al seguente:

Peter,

A site administrator at Website has created an account for you. You may now log in by clicking this link or copying and pasting it to your browser:

[user:one-time-login-url]

This link can only be used once to log in and will lead you to a page where you can set your password.

After setting your password, you will be able to log in at http://localhost/website/user in the future using:

username: Peter
password: Your password

--  Website team

Come puoi vedere, cose come [user: name], [site: name] e [site: login-url] vengono elaborate correttamente. L'unico token che non viene elaborato è [user: one-time-login-url]. Qualche idea sul perché questo stia accadendo?

EDIT: Solo per riferimento, il token non ottenere elaborati nelle e-mail di benvenuto che viene inviati automaticamente dal sistema, in modo che il modulo di token è attiva e funzionante ... Semplicemente non sembra ottenere trasformati quando chiamo manualmente token_replace ().


Il token.module è abilitato? Sembra che quel token sia definito in token_token_info () e non in user_token_info ().
Berdir,

Sì, il modulo token è abilitato e sto usando l'ultima Beta7 ... Questo è piuttosto strano.
Peter,

Risposte:


11

Per sostituire quel token, è necessario chiamare token_replace()come token_replace($email, array('user' => $_user), array('callback' => 'user_mail_tokens', 'sanitize' => FALSE)).

La funzione user_mail_tokens () è descritta nella documentazione come:

Richiamo token per aggiungere token non sicuri per la posta degli utenti.

Questa funzione viene utilizzata dalla chiamata token_replace () alla fine di _user_mail_text () per impostare alcuni token aggiuntivi che possono essere utilizzati nei messaggi di posta elettronica generati da user_mail () .

Il codice utilizzato _user_mail_text()per chiamare quel callback è il seguente.

// We do not sanitize the token replacement, since the output of this
// replacement is intended for an e-mail message, not a web browser.
return token_replace($text, $variables, array('language' => $language, 'callback' => 'user_mail_tokens', 'sanitize' => FALSE));

Il modulo Token non è necessario per sostituire i token, in Drupal 7. Il codice per sostituire i token fa parte del codice core di Drupal 7; il modulo token in Drupal 7 definisce token extra che i moduli core di Drupal non definiscono.

Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.