You are here

public function MediaDirectoriesConfigForm::buildForm in Media Directories 8

Same name and namespace in other branches
  1. 3.x src/Form/MediaDirectoriesConfigForm.php \Drupal\media_directories\Form\MediaDirectoriesConfigForm::buildForm()
  2. 2.x src/Form/MediaDirectoriesConfigForm.php \Drupal\media_directories\Form\MediaDirectoriesConfigForm::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/MediaDirectoriesConfigForm.php, line 62

Class

MediaDirectoriesConfigForm
Media directories configuration form.

Namespace

Drupal\media_directories\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('media_directories.settings');
  $vocabularies = $this->entityTypeManager
    ->getStorage('taxonomy_vocabulary')
    ->loadMultiple();
  $options = [];
  $options[''] = $this
    ->t('- None -');
  foreach ($vocabularies as $vocabulary) {
    $options[$vocabulary
      ->id()] = $vocabulary
      ->label();
  }
  $vocabulary_add_url = Url::fromRoute('entity.taxonomy_vocabulary.add_form')
    ->toString();
  $form['directory_taxonomy'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Taxonomy'),
    '#description' => $this
      ->t('Select taxonomy for directory structure or  <a href=":create_vocabulary_url">create a new one</a>.', [
      ':create_vocabulary_url' => $vocabulary_add_url,
    ]),
    '#options' => $options,
    '#default_value' => $config
      ->get('directory_taxonomy'),
  ];
  $form['all_files_in_root'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show all files in Root directory'),
    '#description' => $this
      ->t('By checking this option, Root directory will show all the files.'),
    '#default_value' => $config
      ->get('all_files_in_root'),
  ];
  return parent::buildForm($form, $form_state);
}