You are here

function s3fs_settings in S3 File System 7

Same name and namespace in other branches
  1. 7.3 s3fs.admin.inc \s3fs_settings()
  2. 7.2 s3fs.admin.inc \s3fs_settings()

Builds the Settings form.

1 string reference to 's3fs_settings'
s3fs_menu in ./s3fs.module
Implements hook_menu().

File

./s3fs.admin.inc, line 11
Administration form setup for S3 File System.

Code

function s3fs_settings() {
  $config = _s3fs_get_config();
  $form = array();

  // I'd like to be able to pull this information directly from the SDK, but
  // I couldn't find a good way to get the human-readable region names.
  $region_map = array(
    '' => 'Default',
    'us-east-1' => 'US Standard (us-east-1)',
    'us-west-1' => 'US West - Northern California  (us-west-1)',
    'us-west-2' => 'US West - Oregon (us-west-2)',
    'eu-west-1' => 'EU - Ireland  (eu-west-1)',
    'eu-central-1' => 'EU - Frankfurt (eu-central-1)',
    'ap-southeast-1' => 'Asia Pacific - Singapore (ap-southeast-1)',
    'ap-southeast-2' => 'Asia Pacific - Sydney (ap-southeast-2)',
    'ap-northeast-1' => 'Asia Pacific - Tokyo (ap-northeast-1)',
    'sa-east-1' => 'South America - Sao Paulo (sa-east-1)',
  );
  $form['s3fs_credentials'] = array(
    '#type' => 'fieldset',
    '#title' => t('Amazon Web Services Credentials'),
    '#description' => t("To configure your Amazon Web Services credentials, enter the values in the appropriate fields below.\n      You may instead set \$conf['awssdk2_access_key'] and \$conf['awssdk2_secret_key'] in your site's settings.php file.\n      Values set in settings.php will override the values in these fields."),
    '#collapsible' => TRUE,
    '#collapsed' => !empty($config['awssdk2_access_key']) || !empty($config['use_instance_profile']),
  );
  $form['s3fs_credentials']['s3fs_awssdk2_access_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Amazon Web Services Access Key'),
    '#default_value' => $access_key = !empty($config['awssdk2_access_key']) ? $config['awssdk2_access_key'] : '',
  );

  // Override with awssdk2_access_key from settings.php, if set.
  $form['s3fs_credentials']['s3fs_awssdk2_access_key']['#default_value'] = variable_get('awssdk2_access_key', $access_key);
  $form['s3fs_credentials']['s3fs_awssdk2_secret_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Amazon Web Services Secret Key'),
    '#default_value' => $secret_key = !empty($config['awssdk2_secret_key']) ? $config['awssdk2_secret_key'] : '',
  );

  // Override with awssdk2_secret_key from settings.php, if set.
  $form['s3fs_credentials']['s3fs_awssdk2_secret_key']['#default_value'] = variable_get('awssdk2_secret_key', $secret_key);
  $form['s3fs_credentials']['s3fs_use_instance_profile'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use EC2 Instance Profile Credentials'),
    '#default_value' => !empty($config['use_instance_profile']) ? $config['use_instance_profile'] : FALSE,
    '#description' => t('If your Drupal site is running on an Amazon EC2 server, you may use the Instance Profile Credentials from that server
      rather than setting your AWS credentials directly.'),
  );
  $form['s3fs_credentials']['s3fs_awssdk2_default_cache_config'] = array(
    '#type' => 'textfield',
    '#title' => t('Default Cache Location'),
    '#description' => t('The default cache location for your EC2 Instance Profile Credentials.'),
    '#default_value' => $cache_config = !empty($config['awssdk2_default_cache_config']) ? $config['awssdk2_default_cache_config'] : '',
    '#states' => array(
      'visible' => array(
        ':input[id=edit-s3fs-use-instance-profile]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );

  // Override with awssdk2_default_cache_config from settings.php, if set.
  $form['s3fs_credentials']['s3fs_awssdk2_default_cache_config']['#default_value'] = variable_get('awssdk2_default_cache_config', $cache_config);
  $form['s3fs_bucket'] = array(
    '#type' => 'textfield',
    '#title' => t('S3 Bucket Name'),
    '#default_value' => !empty($config['bucket']) ? $config['bucket'] : '',
    '#required' => TRUE,
  );
  $form['s3fs_region'] = array(
    '#type' => 'select',
    '#options' => $region_map,
    '#title' => t('S3 Region'),
    '#description' => t('The region in which your bucket resides. Be careful to specify this accurately,
      as you are likely to see strange or broken behavior if the region is set wrong.'),
    '#default_value' => !empty($config['region']) ? $config['region'] : '',
  );
  $form['s3fs_use_cname'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable CNAME'),
    '#description' => t('Serve files from a custom domain by using an appropriately named bucket, e.g. "mybucket.mydomain.com".'),
    '#default_value' => !empty($config['use_cname']) ? $config['use_cname'] : FALSE,
  );
  $form['s3fs_cname_settings_fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t('CNAME Settings'),
    '#states' => array(
      'visible' => array(
        ':input[id=edit-s3fs-use-cname]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['s3fs_cname_settings_fieldset']['s3fs_domain'] = array(
    '#type' => 'textfield',
    '#title' => t('CDN Domain Name'),
    '#description' => t('If serving files from CloudFront, the bucket name can differ from the domain name.'),
    '#default_value' => !empty($config['domain']) ? $config['domain'] : '',
  );
  $form['s3fs_cache_control_header'] = array(
    '#type' => 'textfield',
    '#title' => t('S3 Object Cache-Control Header'),
    '#description' => t('The cache control header to set on all S3 objects for CDNs and browsers, e.g. "public, max-age=300".'),
    '#default_value' => !empty($config['cache_control_header']) ? $config['cache_control_header'] : '',
  );
  $form['s3fs_use_https'] = array(
    '#type' => 'checkbox',
    '#title' => t('Always serve files from S3 via HTTPS'),
    '#description' => t('Forces S3 File System to always generate HTTPS URLs for files in your bucket,
      e.g. "https://mybucket.s3.amazonaws.com/smiley.jpg".<br>
      Without this setting enabled, URLs for your files will use the same scheme as the page they are served from.'),
    '#default_value' => !empty($config['use_https']) ? $config['use_https'] : FALSE,
  );
  $form['s3fs_use_customhost'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use a Custom Host'),
    '#description' => t('Connect to an S3-compatible storage service other than Amazon.'),
    '#default_value' => !empty($config['use_customhost']) ? $config['use_customhost'] : FALSE,
  );
  $form['s3fs_costomhost_settings_fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Custom Host Settings'),
    '#states' => array(
      'visible' => array(
        ':input[id=edit-s3fs-use-customhost]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['s3fs_costomhost_settings_fieldset']['s3fs_hostname'] = array(
    '#type' => 'textfield',
    '#title' => t('Hostname'),
    '#description' => t('Custom service hostname, e.g. "objects.dreamhost.com".'),
    '#default_value' => !empty($config['hostname']) ? $config['hostname'] : '',
    '#states' => array(
      'visible' => array(
        ':input[id=edit-s3fs-use-customhost]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['s3fs_ignore_cache'] = array(
    '#type' => 'checkbox',
    '#title' => t('Ignore the file metadata cache'),
    '#description' => t("If you need to debug a problem with S3, you may want to temporarily ignore the file metadata cache.\n      This will make all filesystem reads hit S3 instead of the cache.<br>\n      <b>This causes s3fs to work extremely slowly, and should never be enabled on a production site.</b>"),
    '#default_value' => !empty($config['ignore_cache']) ? $config['ignore_cache'] : FALSE,
  );
  $form['s3fs_prefix'] = array(
    '#type' => 'textfield',
    '#title' => t('Partial Refresh Prefix'),
    '#default_value' => !empty($config['prefix']) ? $config['prefix'] : '',
    '#description' => t('If you want the "Refresh file metadata cache" action to refresh only some of the contents of your
      bucket, provide a file path prefix in this field.<br>
      For example, setting this option to "images/" will refresh only the files with a URI that matches s3://images/*.
      This setting is case sensitive.'),
  );
  $form['s3fs_presigned_urls'] = array(
    '#type' => 'textarea',
    '#title' => t('Presigned URLs'),
    '#description' => t('A list of timeouts and paths that should be delivered through a presigned url.<br>
      Enter one value per line, in the format timeout|path. e.g. "60|private_files/*". Paths use regex patterns
      as per !link. If no timeout is provided, it defaults to 60 seconds.<br>
      <b>This feature does not work when "Enable CNAME" is used.</b>', array(
      '!link' => l('preg_match', 'http://php.net/preg_match'),
    )),
    '#default_value' => !empty($config['presigned_urls']) ? $config['presigned_urls'] : '',
    '#rows' => 5,
  );
  $form['s3fs_saveas'] = array(
    '#type' => 'textarea',
    '#title' => t('Force Save As'),
    '#description' => t('A list of paths for which users will be forced to save the file, rather than displaying it in the browser.<br>
      Enter one value per line. e.g. "video/*". Paths use regex patterns as per !link.<br>
      <b>This feature does not work when "Enable CNAME" is used.</b>', array(
      '!link' => l('preg_match', 'http://php.net/preg_match'),
    )),
    '#default_value' => !empty($config['saveas']) ? $config['saveas'] : '',
    '#rows' => 5,
  );
  $form['s3fs_torrents'] = array(
    '#type' => 'textarea',
    '#title' => t('Torrents'),
    '#description' => t('A list of paths that should be delivered via BitTorrent.<br>
      Enter one value per line, e.g. "big_files/*". Paths use regex patterns as per !link.<br>
      <b>Paths which are already set as Presigned URLs or Forced Save As cannot be delivered as torrents.</b>', array(
      '!link' => l('preg_match', 'http://php.net/preg_match'),
    )),
    '#default_value' => !empty($config['torrents']) ? $config['torrents'] : '',
    '#rows' => 5,
  );

  // Once the system settings form has been fully set up, add our additional
  // submit callback.
  $form = system_settings_form($form);
  $form['#submit'][] = '_s3fs_amazons3_api_compatibility_submit';
  return $form;
}