You are here

function _amazons3_field_configuration in AmazonS3 7.2

Add S3 configuration to file field settings forms.

Parameters

array &$form: The form to alter.

string $type: The field type being modified.

2 calls to _amazons3_field_configuration()
amazons3_form_field_ui_field_edit_form_alter in ./amazons3.module
Implements hook_form_FORM_ID_alter().
amazons3_form_field_ui_field_settings_form_alter in ./amazons3.module
Implements hook_form_FORM_ID_alter().

File

./amazons3.module, line 564
Hook implementations for the AmazonS3 module.

Code

function _amazons3_field_configuration(array &$form, $type) {
  foreach (amazons3_file_like_field() as $types) {
    if ($type == $types) {
      $settings =& $form['field']['settings'];
      $bucket_setting = isset($form['#field']['settings']['amazons3_bucket']) ? $form['#field']['settings']['amazons3_bucket'] : '';
      $region_setting = isset($form['#field']['settings']['amazons3_region']) ? $form['#field']['settings']['amazons3_region'] : '';
      $settings['uri_scheme']['#weight'] = 50;
      $settings['amazons3_bucket'] = array(
        '#type' => 'textfield',
        '#title' => t('Amazon S3 bucket'),
        '#description' => t('Leave blank to use the site-wide default bucket <a href="@config">currently set to %bucket</a>.', array(
          '@config' => url('admin/config/media/amazons3'),
          '%bucket' => variable_get('amazons3_bucket', ''),
        )),
        '#states' => array(
          'visible' => array(
            ':input[name="field[settings][uri_scheme]"]' => array(
              'value' => 's3',
            ),
          ),
        ),
        '#default_value' => $bucket_setting,
        '#element_validate' => array(
          'amazons3_form_bucket_validate',
        ),
        '#weight' => 51,
      );
      $client = \Aws\S3\S3Client::factory();
      $settings['amazons3_region'] = array(
        '#type' => 'select',
        '#title' => t('Amazon S3 region'),
        '#description' => t('Use <em>default region</em> to use the site-wide default region <a href="@config">currently set to %region</a>.', array(
          '@config' => url('admin/config/media/amazons3'),
          '%region' => variable_get('amazons3_region', ''),
        )),
        '#states' => array(
          'visible' => array(
            ':input[name="field[settings][uri_scheme]"]' => array(
              'value' => 's3',
            ),
          ),
        ),
        '#default_value' => $region_setting,
        '#options' => array(
          0 => t('- default region -'),
        ) + array_combine(array_keys($client
          ->getRegions()), array_keys($client
          ->getRegions())),
        '#weight' => 51,
      );
    }
  }
}