function campaignmonitor_admin_settings_list_edit in Campaign Monitor 7
Same name and namespace in other branches
- 8 includes/campaignmonitor_lists.admin.inc \campaignmonitor_admin_settings_list_edit()
List edit callback that returns a form with information about a given list.
1 string reference to 'campaignmonitor_admin_settings_list_edit'
- campaignmonitor_menu in ./
campaignmonitor.module - Implements hook_menu().
File
- includes/
campaignmonitor_lists.admin.inc, line 98 - Manage the different Campaign Monitor lists.
Code
function campaignmonitor_admin_settings_list_edit($form, &$form_state, $list_id) {
// Confirm that this form has a valid security token present.
_campaignmonitor_admin_verify_access();
$form = [
'#tree' => TRUE,
];
// Get campaign monitor connection.
$cm = CampaignMonitor::getConnector();
// Load extended information about the list.
$list = $cm
->getExtendedList($list_id);
// Add list id to the form.
$form['listId'] = [
'#type' => 'hidden',
'#value' => $list_id,
];
// Set this form name (index).
$form_key = 'campaignmonitor_list_' . $list_id;
// Get previously saved list information.
$defaults = variable_get($form_key, []);
$form[$form_key]['status'] = [
'#type' => 'fieldset',
'#title' => t('Enable list'),
'#description' => t('Enable the list to configure it and use it on the site.'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
];
$form[$form_key]['status']['enabled'] = [
'#type' => 'checkbox',
'#title' => t('Enable'),
'#default_value' => isset($defaults['status']['enabled']) ? $defaults['status']['enabled'] : 1,
'#attributes' => [
'class' => [
'enabled-list-checkbox',
],
],
];
$form[$form_key]['options'] = [
'#type' => 'fieldset',
'#title' => t('List options'),
'#description' => t('Changing the values will result in an update of the values on the Campaign Monitor homepage.'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#states' => [
'visible' => [
'.enabled-list-checkbox' => [
'checked' => TRUE,
],
],
],
];
$form[$form_key]['options']['listname'] = [
'#type' => 'textfield',
'#title' => t('List name'),
'#default_value' => $list['name'],
'#required' => TRUE,
'#states' => [
'visible' => [
':input[name="status[enabled]"]' => [
'checked' => TRUE,
],
],
],
];
$form[$form_key]['options']['UnsubscribePage'] = [
'#type' => 'textfield',
'#title' => t('Unsubscribe page'),
'#default_value' => $list['details']['UnsubscribePage'],
];
$form[$form_key]['options']['ConfirmationSuccessPage'] = [
'#type' => 'textfield',
'#title' => t('Confirmation success page'),
'#default_value' => $list['details']['ConfirmationSuccessPage'],
];
$form[$form_key]['options']['ConfirmedOptIn'] = [
'#type' => 'checkbox',
'#title' => t('Confirmed Opt In'),
'#default_value' => $list['details']['ConfirmedOptIn'],
];
$form[$form_key]['display'] = [
'#type' => 'fieldset',
'#title' => t('Display options'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#states' => [
'visible' => [
'.enabled-list-checkbox' => [
'checked' => TRUE,
],
],
],
];
$form[$form_key]['display']['name'] = [
'#type' => 'checkbox',
'#title' => t('Display Name field'),
'#description' => t('Whether the Name field should be displayed when subscribing.'),
'#default_value' => isset($defaults['display']['name']) ? $defaults['display']['name'] : 0,
'#attributes' => [
'class' => [
'tokenable',
'tokenable-name',
],
],
];
// List custom fields.
if (!empty($list['CustomFields'])) {
$options = [];
foreach ($list['CustomFields'] as $key => $field) {
// Form API can't handle keys with [] in all cases.
$token_form_key = str_replace([
'[',
']',
], '', $key);
$options[$token_form_key] = $field['FieldName'];
}
$form[$form_key]['CustomFields'] = [
'#type' => 'fieldset',
'#title' => t('Custom fields'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#attributes' => [
'class' => [
'tokenable',
'tokenable-custom-fields',
],
],
'#states' => [
'visible' => [
'.enabled-list-checkbox' => [
'checked' => TRUE,
],
],
],
];
$form[$form_key]['CustomFields']['selected'] = [
'#type' => 'checkboxes',
'#title' => t('Available fields'),
'#description' => t('Select the fields that should be displayed on subscription forms.'),
'#options' => $options,
'#default_value' => isset($defaults['CustomFields']['selected']) ? $defaults['CustomFields']['selected'] : [],
];
}
if (module_exists('token')) {
$form[$form_key]['tokens'] = [
'#type' => 'fieldset',
'#title' => t('Field tokens'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
];
$form[$form_key]['tokens']['name'] = [
'#type' => 'textfield',
'#title' => t('Name field'),
'#default_value' => isset($defaults['tokens']['name']) ? $defaults['tokens']['name'] : '[current-user:name]',
'#states' => [
'visible' => [
'.tokenable-name' => [
'checked' => TRUE,
],
],
],
];
if (!empty($list['CustomFields'])) {
foreach ($list['CustomFields'] as $key => $field) {
if ($field['DataType'] == 'MultiSelectMany') {
// We can't handle this type of custom field (with tokens).
continue;
}
// Form API can't handle keys with [] in all cases.
$token_form_key = str_replace([
'[',
']',
], '', $key);
$form[$form_key]['tokens'][$token_form_key] = [
'#type' => 'textfield',
'#title' => t('Custom field (@name)', [
'@name' => $field['FieldName'],
]),
'#default_value' => isset($defaults['tokens'][$token_form_key]) ? $defaults['tokens'][$token_form_key] : '',
'#states' => [
'visible' => [
':input[name="' . $form_key . '[CustomFields][selected][' . $token_form_key . ']' . '"]' => [
'checked' => TRUE,
],
],
],
];
}
}
$form[$form_key]['tokens']['token_tree'] = [
'#theme' => 'token_tree',
];
}
// Give the form system look and feel.
$form = system_settings_form($form);
// Add validation function.
$form['#validate'][] = 'campaignmonitor_admin_settings_list_edit_validate';
return $form;
}