function simplenews_form_user_register_form_alter in Simplenews 7.2
Same name and namespace in other branches
- 8.2 simplenews.module \simplenews_form_user_register_form_alter()
- 8 simplenews.module \simplenews_form_user_register_form_alter()
- 7 simplenews.module \simplenews_form_user_register_form_alter()
- 3.x simplenews.module \simplenews_form_user_register_form_alter()
Implements hook_form_FORM_ID_alter().
Add simplenews subscription fields to user register form. @todo mode this function to another place in the module.
File
- ./
simplenews.module, line 1007 - Simplenews node handling, sent email, newsletter block and general hooks
Code
function simplenews_form_user_register_form_alter(&$form, &$form_state) {
$options = $default_value = $hidden = array();
// Determine the lists to which a user can choose to subscribe.
// Determine to which other list a user is automatically subscribed.
foreach (simplenews_newsletter_get_all() as $newsletter) {
$subscribe_new_account = $newsletter->new_account;
$opt_inout_method = $newsletter->opt_inout;
if (($subscribe_new_account == 'on' || $subscribe_new_account == 'off') && ($opt_inout_method == 'single' || $opt_inout_method == 'double')) {
$options[$newsletter->newsletter_id] = $newsletter->name;
if ($subscribe_new_account == 'on') {
$default_value[] = $newsletter->newsletter_id;
}
}
else {
if ($subscribe_new_account == 'silent' || $subscribe_new_account == 'on' && $opt_inout_method == SIMPLENEWS_OPT_INOUT_HIDDEN) {
$hidden[] = $newsletter->newsletter_id;
}
}
}
if (count($options)) {
// @todo Change this text: use less words;
$form['simplenews'] = array(
'#type' => 'fieldset',
'#description' => t('Select the newsletter(s) to which you wish to subscribe.'),
'#weight' => 5,
);
$form['simplenews']['newsletters'] = array(
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => $default_value,
);
}
if (count($hidden)) {
$form['simplenews_hidden'] = array(
'#type' => 'hidden',
'#value' => implode(',', $hidden),
);
}
}