You are here

public function BundlesSettingsForm::buildForm in Media PDF Thumbnail 8.3

Same name and namespace in other branches
  1. 8.4 src/Form/BundlesSettingsForm.php \Drupal\media_pdf_thumbnail\Form\BundlesSettingsForm::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/BundlesSettingsForm.php, line 66

Class

BundlesSettingsForm
Configure example settings for this site.

Namespace

Drupal\media_pdf_thumbnail\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config(static::SETTINGS);
  foreach ($this
    ->getFieldsList() as $bundleId => $infos) {
    if (!empty($infos['fields'])) {
      $form[$bundleId] = [
        '#type' => 'fieldset',
        '#title' => t($infos['label']),
        '#collapsible' => FALSE,
        '#collapsed' => FALSE,
      ];
      $form[$bundleId][$bundleId . '_field'] = [
        '#type' => 'select',
        '#title' => $this
          ->t('Field to use to generate thumbnail'),
        '#description' => $this
          ->t('The file attached must be pdf type, otherwise it will be ignored.</br>If that field is multivalued, only the first value will be used.'),
        '#options' => $infos['fields'],
        '#default_value' => $config
          ->get($bundleId . '_field'),
      ];
      $form[$bundleId][$bundleId . '_enable'] = [
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Enable'),
        '#default_value' => $config
          ->get($bundleId . '_enable'),
      ];
    }
  }
  return parent::buildForm($form, $form_state);
}