You are here

function campaignmonitor_admin_settings_general in Campaign Monitor 8

Same name and namespace in other branches
  1. 7 includes/campaignmonitor.admin.inc \campaignmonitor_admin_settings_general()

Creates the Campaign Monitor settings form. This is located under the general tab.

Return value

array $form

File

includes/campaignmonitor.admin.inc, line 14
Implementation of the administration interface for the module.

Code

function campaignmonitor_admin_settings_general() {

  // Get account details.
  $account = variable_get('campaignmonitor_account', []);

  // Test if the library has been installed. If it has not been installed an
  // error message will be shown.
  $cm = CampaignMonitor::getConnector();
  $library_path = $cm
    ->getLibraryPath();
  $form['campaignmonitor_account'] = [
    '#type' => 'fieldset',
    '#title' => t('Account details'),
    '#description' => t('Enter your Campaign Monitor account information. See !link for more information.', [
      '!link' => l(t('the Campaign Monitor API documentation'), 'http://www.campaignmonitor.com/api/required/'),
    ]),
    '#collapsible' => empty($account) ? FALSE : TRUE,
    '#collapsed' => empty($account) ? FALSE : TRUE,
    '#tree' => TRUE,
  ];
  $form['campaignmonitor_account']['api_key'] = [
    '#type' => 'textfield',
    '#title' => t('API Key'),
    '#description' => t('Your Campaign Monitor API Key. See <a href="http://www.campaignmonitor.com/api/required/">documentation</a>.'),
    '#default_value' => isset($account['api_key']) ? $account['api_key'] : '',
    '#required' => TRUE,
  ];
  $form['campaignmonitor_account']['client_id'] = [
    '#type' => 'textfield',
    '#title' => t('Client ID'),
    '#description' => t('Your Campaign Monitor Client ID. See <a href="http://www.campaignmonitor.com/api/required/">documentation</a>.'),
    '#default_value' => isset($account['client_id']) ? $account['client_id'] : '',
    '#required' => TRUE,
  ];
  if (!empty($account)) {
    $defaults = variable_get('campaignmonitor_general', []);
    $form['campaignmonitor_general'] = [
      '#type' => 'fieldset',
      '#title' => t('General settings'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#tree' => TRUE,
    ];
    $form['campaignmonitor_general']['cache_timeout'] = [
      '#type' => 'textfield',
      '#title' => t('Cache timeout'),
      '#description' => t('Cache timeout in seconds for stats, subscribers and archive information.'),
      '#size' => 4,
      '#default_value' => isset($defaults['cache_timeout']) ? $defaults['cache_timeout'] : '360',
    ];
    $form['campaignmonitor_general']['library_path'] = [
      '#type' => 'textfield',
      '#title' => t('Library path'),
      '#description' => t('The installation path of the Campaign Monitor library, relative to the Drupal root.'),
      '#default_value' => $library_path ? $library_path : (isset($defaults['library_path']) ? $defaults['library_path'] : ''),
    ];
    $form['campaignmonitor_general']['archive'] = [
      '#type' => 'checkbox',
      '#title' => t('Newsletter archive'),
      '#description' => t('Create a block with links to HTML versions of past campaigns.'),
      '#default_value' => isset($defaults['archive']) ? $defaults['archive'] : 0,
    ];
    $form['campaignmonitor_general']['logging'] = [
      '#type' => 'checkbox',
      '#title' => t('Log errors'),
      '#description' => t('Log communication errors with the Campaign Monitor service, if any.'),
      '#default_value' => isset($defaults['logging']) ? $defaults['logging'] : 0,
    ];
    $form['campaignmonitor_general']['instructions'] = [
      '#type' => 'textfield',
      '#title' => t('Newsletter instructions'),
      '#description' => t('This message will be displayed to the user when subscribing to newsletters.'),
      '#default_value' => isset($defaults['instructions']) ? $defaults['instructions'] : t('Select the newsletters you want to subscribe to.'),
    ];

    // Add cache clear button.
    $form['clear_cache'] = [
      '#type' => 'fieldset',
      '#title' => t('Clear cached data'),
      '#description' => t('The information downloaded from Campaign Monitor is cached to speed up the website. The lists details, custom fields and other data may become outdated if these are changed at Campaign Monitor. Clear the cache to refresh this information.'),
    ];
    $form['clear_cache']['clear'] = [
      '#type' => 'submit',
      '#value' => t('Clear cached data'),
      '#submit' => [
        'campaignmonitor_clear_cache_submit',
      ],
    ];
  }
  $form = system_settings_form($form);
  $form['#submit'][] = 'campaignmonitor_admin_settings_general_submit';
  $form['#validate'][] = 'campaignmonitor_admin_settings_general_validate';
  return $form;
}