You are here

public function BundlesSettingsForm::buildForm in Media PDF Thumbnail 8.4

Same name and namespace in other branches
  1. 8.3 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 64

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'),
      ];
    }
  }
  $form['cron'] = [
    '#type' => 'fieldset',
    '#title' => t('CRON'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
  ];
  $form['cron']['cron_enable'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable cron'),
    '#default_value' => $config
      ->get('cron_enable'),
    '#description' => $this
      ->t('If enabled, thumbnails process will be added in a separate queue for being generated in cron task.'),
  ];
  $form['cron']['cron_time'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Minutes'),
    '#default_value' => $config
      ->get('cron_time'),
    '#description' => $this
      ->t('Default value is 1 minute'),
    '#min' => 1,
  ];
  return parent::buildForm($form, $form_state);
}