You are here

function fastly_setup_form in Fastly 7.2

Same name and namespace in other branches
  1. 7 fastly.admin.inc \fastly_setup_form()

Settings form.

1 string reference to 'fastly_setup_form'
fastly_menu in ./fastly.module
Implements hook_menu().

File

./fastly.admin.inc, line 11
Administrative forms for Fastly module.

Code

function fastly_setup_form($form_state) {
  $api = fastly_get_api();
  $service_id = variable_get('fastly_service_id', '');
  $api_key = variable_get('fastly_api_key', '');
  $form['fastly_api_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Fastly API Key'),
    '#default_value' => $api_key,
    '#required' => TRUE,
    '#description' => t('You can find it on your account settings page. If you dont have an account, please go to <a href="/?q=admin/config/services/fastly/register">registration page</a>'),
  );
  if ($api_key) {
    $services = array();
    foreach ($api
      ->getServices() as $service) {
      $services[$service->id] = $service->name;
    }
    ksort($services);
    $form['fastly_service_id'] = array(
      '#type' => 'radios',
      '#title' => t('Service'),
      '#options' => $services,
      '#default_value' => $service_id,
      '#required' => TRUE,
      '#description' => t('A Service represents the configuration for your website to be served through Fastly.'),
    );
    $form['actions']['new_service'] = array(
      '#markup' => l(t('New service'), 'admin/config/services/fastly/new', array(
        'attributes' => array(
          'class' => 'button',
        ),
      )),
      '#weight' => 10,
    );
  }
  $default_ttl = $api
    ->getSetting('general.default_ttl');
  $form['fastly_ttl'] = array(
    '#type' => 'textfield',
    '#title' => t('Default TTL'),
    '#default_value' => $default_ttl ? $default_ttl : '',
    '#description' => t('The default time to live for cached content in seconds.'),
  );
  $description = t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array(
    '%blog' => 'blog',
    '%blog-wildcard' => 'blog/*',
    '%front' => '<front>',
  ));
  $form['fastly_non_cached'] = array(
    '#type' => 'textarea',
    '#title' => t('Non-cached pages'),
    '#default_value' => variable_get('fastly_non_cached', ''),
    '#description' => $description,
  );
  if (module_exists('httprl')) {
    $form['fastly_purge_endpoint'] = array(
      '#type' => 'textfield',
      '#title' => t('Purge endpoint'),
      '#default_value' => variable_get('fastly_purge_endpoint', NULL),
      '#description' => t('Alternative PURGE request endpoint, use your <a href="@cname-url">Fastly CNAME hostname</a> if an HTTP request to %base_url from your server would not go through Fastly.', array(
        '%base_url' => $GLOBALS['base_url'],
        '@cname-url' => 'https://docs.fastly.com/guides/basic-setup/adding-cname-records',
      )),
    );
  }
  $form['fastly_purge_type'] = array(
    '#type' => 'radios',
    '#title' => t('Purging'),
    '#options' => array(
      'soft' => 'Soft purge',
      'immediate' => 'Immediate purge',
    ),
    '#default_value' => variable_get('fastly_purge_type', 'immediate'),
    '#required' => TRUE,
    '#description' => t('Purge of cached items may be immediate or delayed (soft). Soft purge means Fastly will deliver the existing cache until new data is fetched from the origin.'),
  );
  $form['#submit'][] = 'fastly_setup_form_submit';
  return system_settings_form($form);
}