function constant_contact_form_user_profile_form_alter in Constant Contact 7.3
Implements hook_form_FORM_ID_alter().
File
- ./
constant_contact.module, line 381
Code
function constant_contact_form_user_profile_form_alter(&$form, &$form_state) {
$subscribe_method = variable_get('cc_register_page_method', CC_REGISTER_PAGE_METHOD);
$list_format = variable_get('cc_list_selection_format', CC_LIST_SELECTION_FORMAT);
$show_format_choice = variable_get('cc_show_format_choice', CC_SHOW_FORMAT_CHOICE);
if ($subscribe_method == 'none') {
return;
}
$cc = constant_contact_create_object();
if (!is_object($cc)) {
return;
}
$selected_lists = array();
// check if user is subscribed
$contact = $cc
->query_contacts($form_state['user']->mail);
// user is subscribed so load their options
if ($contact) {
// get full contact details including lists their subscribed to
$contact = $cc
->get_contact($contact['id']);
$default_subscribe_format = $contact['EmailType'];
}
else {
$default_subscribe_format = variable_get('cc_subscribe_format', CC_SUBSCRIBE_FORMAT);
}
if ($subscribe_method == 'lists') {
$show_lists = variable_get('cc_lists', array());
$lists = constant_contact_get_lists($cc);
// if the user is subscribed select the lists they are subscribed to
if ($lists && $contact && $contact['Status'] == 'Active') {
foreach ($contact['lists'] as $list_id) {
$selected_lists[] = $list_id;
}
}
$options = array();
// if they have selected some lists to show build them otherwise show all lists
if (count($show_lists) > 0) {
foreach ($show_lists as $list_id) {
if (array_key_exists($list_id, $lists)) {
$options[$list_id] = $lists[$list_id];
}
}
}
else {
// displaqy all lists
$options = $lists;
}
if (count($options) > 0) {
if ($list_format == 'select') {
$field_type = 'select';
}
else {
$field_type = 'checkboxes';
}
$form['account']['cc_newsletter_lists'] = array(
'#type' => $field_type,
'#title' => variable_get('cc_signup_title', CC_SIGNUP_TITLE),
'#description' => variable_get('cc_signup_description', CC_SIGNUP_DESCRIPTION),
'#options' => $options,
'#weight' => 11,
'#default_value' => $selected_lists,
);
if ($list_format == 'select') {
$field_size = $options && count($options) > 25 ? 25 : count($options);
$form['account']['cc_newsletter_lists']['#multiple'] = TRUE;
$form['account']['cc_newsletter_lists']['#size'] = $field_size;
}
}
}
else {
$form['account']['cc_newsletter'] = array(
'#type' => 'checkbox',
'#title' => variable_get('cc_signup_title', CC_SIGNUP_TITLE),
'#description' => variable_get('cc_signup_description', CC_SIGNUP_DESCRIPTION),
'#weight' => 10,
);
// if the user is subscribed check the checkbox
if ($contact && $contact['Status'] == 'Active') {
$form['account']['cc_newsletter']['#default_value'] = 1;
}
}
if ($show_format_choice) {
$form['account']['cc_email_format'] = array(
'#type' => 'radios',
'#title' => t('Email Format'),
'#description' => 'You can receive emails in Text or HTML format',
'#weight' => 12,
'#default_value' => $default_subscribe_format,
'#options' => $default_subscribe_format == 'HTML' ? array(
'HTML' => t('HTML'),
'Text' => t('Text'),
) : array(
'Text' => t('Text'),
'HTML' => t('HTML'),
),
);
}
return $form;
}