You are here

public function S3fsCorsAdminForm::buildForm in S3 File System CORS Upload 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/S3fsCorsAdminForm.php, line 70

Class

S3fsCorsAdminForm
Config settings for S3FS Cors.

Namespace

Drupal\s3fs_cors\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('s3fs_cors.settings');
  $form['s3fs_cors_origin'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('CORS Origin'),
    '#description' => $this
      ->t('Please enter the URL from which your users access this website, e.g. <i>www.example.com</i>.
      You may optionally specifiy up to one wildcard, e.g. <i>*.example.com</i>.<br>
      Upon submitting this form, if this field is filled, your S3 bucket will be configured to allow CORS
      requests from the specified origin. If the field is empty, your bucket\'s CORS config will be deleted.'),
    '#default_value' => !empty($config
      ->get('s3fs_cors_origin')) ? $config
      ->get('s3fs_cors_origin') : '',
  ];
  $form['s3fs_https'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Use Https/Http'),
    '#description' => $this
      ->t('Select what method you will like to use with your bucket'),
    '#default_value' => !empty($config
      ->get('s3fs_https')) ? $config
      ->get('s3fs_https') : 'http',
    '#options' => [
      'http' => $this
        ->t('HTTP'),
      'https' => $this
        ->t('HTTPS'),
    ],
  ];
  $form['s3fs_access_type'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Access Type on File Uploads'),
    '#description' => $this
      ->t('Select what access permission should be there on File Upload.'),
    '#default_value' => !empty($config
      ->get('s3fs_access_type')) ? $config
      ->get('s3fs_access_type') : 'public-read',
    '#options' => [
      'public-read' => $this
        ->t('Public Read'),
      'private' => $this
        ->t('Private'),
    ],
  ];
  $form = parent::buildForm($form, $form_state);
  return $form;
}