function party_subscription_settings_edit_form in Party 8.2
Party subscription settings edit form
1 string reference to 'party_subscription_settings_edit_form'
- party_simplenews_party_data_set_info in modules/
party_simplenews/ party_simplenews.module - Implements hook_party_data_set_info() {
File
- modules/
party_simplenews/ party_subscription_settings.api.inc, line 112 - Helper functions etc for the subscription settings
Code
function party_subscription_settings_edit_form($form, &$form_state, &$attached_entity, $party) {
if (empty($party->pid)) {
return FALSE;
}
$simplenews_form = array();
// Get all the emails on the party.
$options = $emails = party_get_all_emails($party);
foreach ($options as $key => $email) {
$options[$key] .= ' (Primary)';
break;
}
$hash = 'subscription_settings:' . $attached_entity->subscription_settings_id;
$current_ref = !empty($form_state['values'][$hash]['field_ref']) ? $form_state['values'][$hash]['field_ref'] : reset(array_keys($emails));
if (!empty($form_state['triggering_element']) && $form_state['triggering_element']['#name'] == $hash . '[field_ref]') {
unset($form_state['values'][$hash]);
unset($form_state['input'][$hash]);
}
$simplenews_form['field_ref'] = array(
'#type' => 'select',
'#title' => t('Email'),
'#options' => $options,
'#default_value' => $current_ref,
'#ajax' => array(
'callback' => 'party_subscription_settings_edit_form_ajax',
'wrapper' => 'simplenews-subscriptions',
'method' => 'replace',
'effect' => 'fade',
),
'#attributes' => array(
'autocomplete' => 'off',
),
);
module_load_include('inc', 'simplenews', 'includes/simplenews.subscription');
$subscriber = party_simplenews_subscriber_load_by_pid($party->pid, $current_ref);
// If this email doesn't have a subscriber yet, create one
if (!$subscriber) {
$subscriber = new stdClass();
$subscriber->mail = $emails[$current_ref];
$subscriber->activated = 1;
$subscriber->language = '';
$subscriber->uid = 0;
$subscriber->party_id = $party->pid;
$subscriber->party_field_ref = $current_ref;
simplenews_subscriber_save($subscriber);
}
simplenews_subscriptions_account_form($simplenews_form, $form_state, $subscriber);
unset($simplenews_form['#submit']);
$simplenews_form['subscriptions']['#prefix'] = '<div id="simplenews-subscriptions">';
$simplenews_form['subscriptions']['#suffix'] = '</div>';
return $simplenews_form;
}