You are here

public function SettingsForm::buildForm in Private files download permission 3.x

Same name and namespace in other branches
  1. 8.2 src/Form/SettingsForm.php \Drupal\pfdp\Form\SettingsForm::buildForm()

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/SettingsForm.php, line 30

Class

SettingsForm
Settings form for private_files_download_permission.

Namespace

Drupal\pfdp\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $settings = \Drupal::config('pfdp.settings');

  // Prepare the fields.
  $form['by_user_checks'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable by-user checks'),
    '#default_value' => $settings
      ->get('by_user_checks'),
    '#description' => $this
      ->t('You may wish to disable this feature if there are plenty of users, as it may slow down the entire site.'),
  ];
  $form['cache_users'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Cache user list'),
    '#default_value' => $settings
      ->get('cache_users'),
    '#description' => $this
      ->t('For sites with lots of users, this will save on load time when editing directory settings.'),
    '#states' => [
      'visible' => [
        ':input[name="by_user_checks"]' => [
          'checked' => TRUE,
        ],
      ],
      'enabled' => [
        ':input[name="by_user_checks"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['attachment_mode'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable attachment mode'),
    '#default_value' => $settings
      ->get('attachment_mode'),
    '#description' => $this
      ->t('Have files downloaded as attachments instead of displayed inline in the browser.'),
  ];
  $form['override_mode'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable override mode'),
    '#default_value' => $settings
      ->get('override_mode'),
    '#description' => $this
      ->t('Skip the system-wide validation chain and download files immediately.'),
  ];
  $form['debug_mode'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable debug mode'),
    '#default_value' => $settings
      ->get('debug_mode'),
    '#description' => $this
      ->t('Turn on logging to debug issues.'),
  ];

  // Prepare the submit button.
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save settings'),
  ];

  // Return the form.
  return $form;
}