You are here

function acquia_lift_admin_form in Acquia Lift Connector 7.2

Same name and namespace in other branches
  1. 7.3 acquia_lift.admin.inc \acquia_lift_admin_form()
  2. 7 acquia_lift.admin.inc \acquia_lift_admin_form()

Admin form for configuring personalization backends.

1 string reference to 'acquia_lift_admin_form'
acquia_lift_configuration_page in ./acquia_lift.admin.inc
Menu callback for the Acquia Lift settings page.

File

./acquia_lift.admin.inc, line 25
acquia_lift.admin.inc Provides functions needed for the admin UI.

Code

function acquia_lift_admin_form($form, &$form_state) {
  $form = array(
    '#attached' => array(
      'css' => array(
        drupal_get_path('module', 'acquia_lift') . '/css/acquia_lift.admin.css',
      ),
    ),
  );
  $account_info = acquia_lift_get_account_info();
  $account_info_provided = !empty($account_info['public_key']) && !empty($account_info['private_key']);
  if ($account_info_provided) {

    // Add a button for checking the connection.
    $form['ping_test_wrapper'] = array(
      '#theme_wrappers' => array(
        'container',
      ),
      '#attributes' => array(
        'id' => 'acquia-lift-config-messages',
      ),
    );
    $form['ping_test'] = array(
      '#type' => 'submit',
      '#value' => t('Test connection to Acquia Lift'),
      '#attributes' => array(
        'title' => t('Click here to check your Acquia Lift connection.'),
      ),
      '#submit' => array(
        'acquia_lift_ping_test_submit',
      ),
      '#ajax' => array(
        'callback' => 'acquia_lift_ping_test_ajax_callback',
        'wrapper' => 'acquia-lift-ping-test',
        'effect' => 'fade',
      ),
      '#limit_validation_errors' => array(),
    );
  }
  $form['acquia_lift_account_info'] = array(
    '#type' => 'fieldset',
    '#title' => 'Acquia Lift Account Settings',
    '#tree' => FALSE,
    '#collapsible' => TRUE,
    '#collapsed' => $account_info_provided,
  );
  if ($account_info_provided) {
    $form['acquia_lift_account_info']['msg'] = array(
      '#markup' => t("<p>We automatically obtained your Lift Decision credentials from your Acquia Account. Everything is good to go!</p>", array(
        '!acquialift' => l(t('Acquia Lift'), 'http://www.acquia.com/products-services/website-personalization', array(
          'attributes' => array(
            'target' => '_blank',
          ),
        )),
        '!advocacyemail' => l('advocacy@acquia.com', 'mailto:advocacy@acquia.com'),
      )),
    );
    $form['acquia_lift_account_info']['public_key'] = array(
      '#markup' => t("<p>Public Key: <strong>!publickey</strong></p>", array(
        '!publickey' => $account_info['public_key'],
      )),
    );
    $form['acquia_lift_account_info']['apiurl'] = array(
      '#markup' => t("<p>API URL: <strong>!apiurl</strong></p>", array(
        '!apiurl' => $account_info['api_url'],
      )),
    );
  }
  else {
    $form['acquia_lift_account_info']['msg'] = array(
      '#markup' => t("<p>It doesn't look like we could find your credentials. Have you enabled and configured the Acquia Connector module? Please contact support if you have purchased Acquia Lift and are connected with the Acquia Connector, otherwise, contact !advocacyemail to purchase a subscription to the !acquialift service.</p>", array(
        '!acquialift' => l(t('Acquia Lift'), 'http://www.acquia.com/products-services/website-personalization', array(
          'attributes' => array(
            'target' => '_blank',
          ),
        )),
        '!advocacyemail' => l('advocacy@acquia.com', 'mailto:advocacy@acquia.com'),
      )),
    );
  }

  // Add in the JS path.
  $js_path_desc = false;
  $default_path = variable_get('acquia_lift_profiles_js_path', '');
  if (isset($account_info['js_path']) && $account_info['js_path'] != $default_path) {
    $js_path_desc = t("Suggested: !js_path", array(
      '!js_path' => $account_info['js_path'],
    ));
    $default_path = $account_info['js_path'];
  }

  // Lift Web account info.
  $form['acquia_lift_account_info']['acquia_lift_profiles_js_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Acquia Lift JavaScript path'),
    '#field_prefix' => 'http(s)://',
    '#default_value' => variable_get('acquia_lift_profiles_js_path', $default_path),
    '#required' => TRUE,
    '#description' => $js_path_desc ? $js_path_desc : false,
  );
  if ($account_info['profiles']['account_name'] != "") {
    $acc_name_desc = t("Short abbreviation of your account name. Suggested: @accountname", array(
      '@accountname' => $account_info['profiles']['account_name'],
    ));
  }
  else {
    $acc_name_desc = t("Short abbreviation of your account name, such as MYACCOUNT01.");
  }
  $form['acquia_lift_account_info']['acquia_lift_profiles_account_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Acquia Lift Web Account Name'),
    '#default_value' => variable_get('acquia_lift_profiles_account_name', $account_info['profiles']['account_name']),
    '#description' => $acc_name_desc,
    '#required' => TRUE,
  );
  $form['acquia_lift_account_info']['acquia_lift_profiles_site_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Acquia Lift Web Customer Site'),
    '#default_value' => variable_get('acquia_lift_profiles_site_name', ''),
    '#description' => t("When you are using multiple sites with the same Acquia Lift Web account, use this. Otherwise, leave it empty"),
  );
  $form['acquia_lift_account_info']['acquia_lift_profiles_api_url'] = array(
    '#type' => 'textfield',
    '#title' => t('Acquia Lift Web API URL'),
    '#field_prefix' => 'http(s)://',
    '#default_value' => variable_get('acquia_lift_profiles_api_url', $account_info['profiles']['hostname']),
    '#description' => t("Server where your Acquia Lift Web account resides."),
    '#required' => TRUE,
  );
  if ($account_info['profiles']['public_key'] != "" && variable_get('acquia_lift_profiles_access_key', '') == "<reset>") {
    $public_key_desc = t("Suggested: @public_key", array(
      '@public_key' => $account_info['profiles']['public_key'],
    ));
  }
  else {
    $public_key_desc = t("Write %reset in the field to show the access key", array(
      "%reset" => "<reset>",
    ));
  }
  $form['acquia_lift_account_info']['acquia_lift_profiles_access_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Acquia Lift Web API Access Key'),
    '#default_value' => variable_get('acquia_lift_profiles_access_key', $account_info['profiles']['public_key']),
    '#description' => $public_key_desc,
    '#required' => TRUE,
  );
  if ($account_info['profiles']['secret_key'] != "" && variable_get('acquia_lift_profiles_secret_key', '') == "<reset>") {
    $secret_key_desc = t("Suggested: @secret_key", array(
      '@secret_key' => $account_info['profiles']['secret_key'],
    ));
  }
  else {
    $secret_key_desc = t("Write %reset in the field to show the secret key", array(
      "%reset" => "<reset>",
    ));
  }
  $form['acquia_lift_account_info']['acquia_lift_profiles_secret_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Acquia Lift Web API Secret Key'),
    '#default_value' => variable_get('acquia_lift_profiles_secret_key', $account_info['profiles']['secret_key']),
    '#description' => $secret_key_desc,
    '#required' => TRUE,
  );
  $form['acquia_lift_confidence_measure'] = array(
    '#type' => 'textfield',
    '#title' => t('Confidence measure'),
    '#size' => 3,
    '#field_suffix' => '%',
    '#required' => TRUE,
    '#default_value' => variable_get('acquia_lift_confidence_measure', 95),
    '#description' => t('The confidence percentage at which a test is considered statistically significant.'),
    '#element_validate' => array(
      'element_validate_number',
    ),
  );
  $form['acquia_lift_report_max_days'] = array(
    '#type' => 'textfield',
    '#title' => t('Reporting history duration'),
    '#size' => 3,
    '#required' => TRUE,
    '#default_value' => variable_get('acquia_lift_report_max_days', ACQUIA_LIFT_DEFAULT_MAX_DAYS),
    '#field_suffix' => t(' days'),
    '#description' => t('The maximum number of days for which to show reporting history.'),
    '#element_validate' => array(
      'element_validate_integer_positive',
    ),
  );
  $form = system_settings_form($form);
  $form['#submit'][] = 'acquia_lift_admin_form_submit';
  return $form;
}