我对Drupal来说几乎是全新的,我正在开展一个项目,我们的目标之一是在注册后向一组用户发送不同的注册电子邮件。我的想法是创建一个可以在电子邮件中使用的令牌,该令牌将由用户的角色决定。我进入了user.module并添加了这个。 角色;
if($welcomer == 'Student Member'){
$copying = "SPECIAL EMAIL TEXT";
}
else{
$copying = "GENERAL EMAIL TEXT";
} ?>
然后在令牌部分我设置了
<?php '!sendit' => $copying, ?>
到目前为止,如果使用,它什么都不做,甚至else语句都无法触发。所以我的问题是,我该怎么做呢?这是最佳方式还是有更简单的方法呢?
答案 0 :(得分:0)
Don't hack the Drupal core或者当您更新Drupal时,您的所有代码都将丢失。
我目前没有可以测试的环境,所以这段代码没有经过测试但你想要这样的东西:
function yourModuleName_form_user_register_alter(&$form, &$form_state) {
// Add your own function to the array of submit callbacks
$form['#submit'][] = 'yourModuleName_user_register_submit';
}
function yourModuleName_user_register_submit($form, &$form_state) {
// I don't think this line is correct but don't have an environment to test in at the moment
// Do a print_r here on $form_state['values'] and see where the user roles are stored
$roles = $form_state['values']['roles'];
if(in_array('Student Member', $roles) {
// send student email here
} elseif(in_array('Teacher Member', $roles) {
// send teacher email here
}
}