You are here

function akamai_settings_form in Akamai 7.3

Form builder to manage Akamai settings.

1 string reference to 'akamai_settings_form'
akamai_menu in ./akamai.module
Implements hook_menu().

File

./akamai.admin.inc, line 14
Administrative pages for the Akamai module.

Code

function akamai_settings_form() {
  $form = array();
  $form['disable_fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Disable akamai cache clearing'),
    '#description' => t('Set this field to disable purge request submissions. Purge requests will still be queued if queueing is enabled. This can be useful when performing imports, migrations, or other batch processes.'),
  );
  $form['disable_fieldset']['akamai_disabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Disable cache purging'),
    '#default_value' => variable_get('akamai_disabled', FALSE),
  );
  $form['cron'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#title' => t('Cron tasks'),
  );
  $form['cron']['akamai_queue_purge_requests'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable queueing of purge requests'),
    '#default_value' => variable_get('akamai_queue_purge_requests', FALSE),
    '#description' => t('If enabled, purge requests will be queued and submitted when cron runs.'),
  );
  $form['cron']['akamai_queue_on_failure'] = array(
    '#type' => 'checkbox',
    '#title' => t('Queue failed purge requests'),
    '#default_value' => variable_get('akamai_queue_on_failure', TRUE),
    '#description' => t('If a purge request fails, the paths will be added to the queue and re-submitted when cron runs.'),
  );
  $form['cron']['akamai_batch_size'] = array(
    '#type' => 'textfield',
    '#title' => t('Batch size'),
    '#default_value' => variable_get('akamai_batch_size', 0),
    '#size' => 7,
    '#maxlength' => 6,
    '#description' => t("The number of queued items to submit in each batch. Set to 0 for no limit, in which case the batch size will be limited by the CCU API request body limit of 50,000 bytes."),
  );
  $form['cron']['akamai_cron_queue_time_limit'] = array(
    '#type' => 'textfield',
    '#title' => t('Cron time limit'),
    '#description' => t("Items in the queue will stop being processed if this time limit is reached."),
    '#size' => 5,
    '#maxlength' => 3,
    '#field_suffix' => t('seconds'),
    '#default_value' => variable_get('akamai_cron_queue_time_limit', AKAMAI_CRON_QUEUE_TIME_LIMIT_DEFAULT),
    '#required' => TRUE,
  );
  $form['cron']['akamai_purge_log_duration_complete'] = array(
    '#type' => 'textfield',
    '#title' => t('How long should information about completed purge requests be kept?'),
    '#size' => 5,
    '#maxlength' => 4,
    '#field_suffix' => t('hours'),
    '#default_value' => variable_get('akamai_purge_log_duration_complete', AKAMAI_PURGE_REQUEST_HOURS_TO_KEEP_DEFAULT),
    '#required' => TRUE,
    '#description' => t('Set to 0 to keep indefinitely.'),
  );
  $form['cron']['akamai_purge_log_duration_incomplete'] = array(
    '#type' => 'textfield',
    '#title' => t('How long should information about pending purge requests be kept?'),
    '#size' => 5,
    '#maxlength' => 4,
    '#field_suffix' => t('hours'),
    '#default_value' => variable_get('akamai_purge_log_duration_incomplete', AKAMAI_PURGE_REQUEST_HOURS_TO_KEEP_DEFAULT),
    '#required' => TRUE,
    '#description' => t('Set to 0 to keep indefinitely.'),
  );
  $form['credentials'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#title' => t('API Credentials'),
    '#description' => t("For instructions on obtaining credentials, see Akamai's <a href=\"!url\">Authorize Your Client</a> documentation.", array(
      '!url' => 'https://developer.akamai.com/introduction/Prov_Creds.html',
    )),
  );
  $form['credentials']['akamai_credential_storage'] = array(
    '#type' => 'radios',
    '#title' => t('Credential storage method'),
    '#default_value' => variable_get('akamai_credential_storage', 'database'),
    '#options' => array(
      'database' => t('Database'),
      'file' => t('.edgerc file'),
    ),
    '#required' => TRUE,
    '#description' => t('Credentials may be stored in the database or in a file. See the README file for more information.'),
  );
  $database_field_states = array(
    'required' => array(
      ':input[name="akamai_credential_storage"]' => array(
        'value' => 'database',
      ),
    ),
    'visible' => array(
      ':input[name="akamai_credential_storage"]' => array(
        'value' => 'database',
      ),
    ),
    'optional' => array(
      ':input[name="akamai_credential_storage"]' => array(
        'value' => 'file',
      ),
    ),
    'invisible' => array(
      ':input[name="akamai_credential_storage"]' => array(
        'value' => 'file',
      ),
    ),
  );
  $file_field_states = array(
    'required' => array(
      ':input[name="akamai_credential_storage"]' => array(
        'value' => 'file',
      ),
    ),
    'visible' => array(
      ':input[name="akamai_credential_storage"]' => array(
        'value' => 'file',
      ),
    ),
    'optional' => array(
      ':input[name="akamai_credential_storage"]' => array(
        'value' => 'database',
      ),
    ),
    'invisible' => array(
      ':input[name="akamai_credential_storage"]' => array(
        'value' => 'database',
      ),
    ),
  );
  $form['credentials']['akamai_base_uri'] = array(
    '#type' => 'textfield',
    '#title' => t('Base URL'),
    '#default_value' => variable_get('akamai_base_uri', ''),
    '#description' => t('Should be in format of %url', array(
      '%url' => 'https://akaa-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx.luna.akamaiapis.net/',
    )),
    '#states' => $database_field_states,
    '#element_validate' => array(
      'akamai_settings_form_validate_credential_field',
      'akamai_settings_form_validate_url',
    ),
    '#akamai_credential_type' => 'database',
  );
  $form['credentials']['akamai_access_token'] = array(
    '#type' => 'textfield',
    '#title' => t('Access token'),
    '#default_value' => variable_get('akamai_access_token', ''),
    '#description' => t('Should be in format of %token', array(
      '%token' => 'akab-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx',
    )),
    '#states' => $database_field_states,
    '#element_validate' => array(
      'akamai_settings_form_validate_credential_field',
    ),
    '#akamai_credential_type' => 'database',
  );
  $form['credentials']['akamai_client_token'] = array(
    '#type' => 'textfield',
    '#title' => t('Client token'),
    '#default_value' => variable_get('akamai_client_token', ''),
    '#description' => t('Should be in format of %token', array(
      '%token' => 'akab-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx',
    )),
    '#states' => $database_field_states,
    '#element_validate' => array(
      'akamai_settings_form_validate_credential_field',
    ),
    '#akamai_credential_type' => 'database',
  );
  $form['credentials']['akamai_client_secret'] = array(
    '#type' => 'textfield',
    '#title' => t('Client secret'),
    '#default_value' => variable_get('akamai_client_secret', ''),
    '#states' => $database_field_states,
    '#element_validate' => array(
      'akamai_settings_form_validate_credential_field',
    ),
    '#akamai_credential_type' => 'database',
  );
  $form['credentials']['akamai_edgerc_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path to .edgerc file'),
    '#default_value' => variable_get('akamai_edgerc_path', ''),
    '#states' => $file_field_states,
    '#element_validate' => array(
      'akamai_settings_form_validate_credential_field',
      'akamai_settings_form_validate_file_exists',
      'akamai_settings_form_validate_file_is_readable',
    ),
    '#akamai_credential_type' => 'file',
  );
  $form['credentials']['akamai_edgerc_section'] = array(
    '#type' => 'textfield',
    '#title' => t('Section of .edgerc file to use for the CCU API'),
    '#default_value' => variable_get('akamai_edgerc_section', 'default'),
    '#states' => $file_field_states,
    '#element_validate' => array(
      'akamai_settings_form_validate_credential_field',
    ),
    '#akamai_credential_type' => 'file',
  );
  $default_hostname = parse_url($GLOBALS['base_url'], PHP_URL_HOST);
  $form['akamai_hostname'] = array(
    '#type' => 'textfield',
    '#title' => t('Hostname'),
    '#default_value' => variable_get('akamai_hostname', $default_hostname),
    '#description' => t('The hostname that contains objects (paths) you want to purge, e.g. "www.example.com"'),
    '#required' => TRUE,
  );
  if (drupal_multilingual()) {
    $form['akamai_use_language_domain'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use language domain for hostname.'),
      '#default_value' => variable_get('akamai_use_language_domain', FALSE),
      '#description' => t('For multilingual sites, you may need to purge from multiple hostnames. Checking this box will cause the language domains specified in the <a href="!url">language settings</a> to be used as the hostname when submitting purge requests.', array(
        '!url' => url('admin/config/regional/language'),
      )),
    );
  }
  $form['akamai_timeout'] = array(
    '#type' => 'textfield',
    '#title' => t('Timeout length'),
    '#description' => t("The timeout used by when sending the cache purge request to Akamai's servers. Most users will not need to change this value."),
    '#size' => 5,
    '#maxlength' => 3,
    '#default_value' => variable_get('akamai_timeout', EdgeGridClient::DEFAULT_REQUEST_TIMEOUT),
    '#required' => TRUE,
  );
  $form['akamai_network'] = array(
    '#type' => 'radios',
    '#title' => t('Domain'),
    '#default_value' => variable_get('akamai_network', CcuClientInterface::NETWORK_PRODUCTION),
    '#options' => array(
      CcuClientInterface::NETWORK_STAGING => t('Staging'),
      CcuClientInterface::NETWORK_PRODUCTION => t('Production'),
    ),
    '#description' => t('The Akamai network to use for cache purge requests.'),
    '#required' => TRUE,
  );
  $form['akamai_action'] = array(
    '#type' => 'radios',
    '#title' => t('Purge action'),
    '#default_value' => variable_get('akamai_action', 'invalidate'),
    '#options' => array(
      'remove' => t('Remove'),
      'invalidate' => t('Invalidate'),
    ),
    '#description' => t('The default purging action. The options are <em>remove</em> (which removes the item from the Akamai cache) and <em>invalidate</em> (which leaves the item in the cache, but invalidates it so that the origin will be hit on the next request.)'),
    '#required' => TRUE,
  );
  return system_settings_form($form);
}