function mailchimp_lists_add_to_segment_action_form in Mailchimp 7.4
Same name and namespace in other branches
- 7.5 modules/mailchimp_lists/mailchimp_lists.module \mailchimp_lists_add_to_segment_action_form()
- 7.3 modules/mailchimp_lists/mailchimp_lists.module \mailchimp_lists_add_to_segment_action_form()
An action configuration form for performing Add To Segment actions.
File
- modules/
mailchimp_lists/ mailchimp_lists.module, line 751
Code
function mailchimp_lists_add_to_segment_action_form($context, &$form_state) {
$form = array();
$mailchimp_field_options = array();
$form_state['mc_list_ids'] = array();
foreach ($context['settings']['mailchimp_field'] as $field) {
if ($info = field_info_field($field)) {
$form_state['mc_list_ids'][$field] = $info['settings']['mc_list_id'];
$bundle = reset($info['bundles'][$context['entity_type']]);
$instance_info = field_info_instance($context['entity_type'], $field, $bundle);
$mailchimp_field_options[$field] = t("@label (@fieldname)", array(
'@label' => $instance_info['label'],
'@fieldname' => $field,
));
}
}
$form['mailchimp_field'] = array(
'#type' => 'select',
'#title' => t('Select a Mailchimp List'),
'#options' => $mailchimp_field_options,
'#required' => TRUE,
'#ajax' => array(
'callback' => 'mailchimp_lists_segment_action_callback',
'wrapper' => 'segment-wrapper',
),
);
if (empty($form_state['values']['mailchimp_field'])) {
$form['segment'] = array(
'#prefix' => '<div id="segment-wrapper">',
'#suffix' => '</div>',
);
}
else {
$segments = mailchimp_get_segments($form_state['mc_list_ids'][$form_state['values']['mailchimp_field']]);
$seg_options = array(
0 => '-- Create New Segment --',
);
foreach ($segments['static'] as $segment) {
$seg_options[$segment['id']] = $segment['name'];
}
$form['segment'] = array(
'#type' => 'select',
'#title' => "Select a tag to add subscribed entities to.",
'#description' => "Only records that have the appropriate list field on their bundle, and are already subscribed to the list, will be added.",
'#id' => 'segment-wrapper',
'#options' => $seg_options,
);
}
$form['new_segment'] = array(
'#type' => 'textfield',
'#title' => "Name for your new tag",
'#states' => array(
'required' => array(
':input[name="segment"]' => array(
'value' => 0,
),
),
'visible' => array(
':input[name="segment"]' => array(
'value' => 0,
),
),
'invisible' => array(
':input[name="mailchimp_field"]' => array(
'value' => '',
),
),
),
);
return $form;
}