You are here

public function ImageStyleWarmerSettingsForm::buildForm in Image Style Warmer 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/ImageStyleWarmerSettingsForm.php, line 30

Class

ImageStyleWarmerSettingsForm
Provides a form for creating and editing Image Style Warmer settings.

Namespace

Drupal\image_style_warmer\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->configFactory()
    ->getEditable('image_style_warmer.settings');
  $imageStyleOptions = image_style_options(FALSE);
  $initialImageStyles = $config
    ->get('initial_image_styles');
  $form['initial_image_styles'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Initial image styles'),
    '#description' => $this
      ->t('Select image styles which will be created initial for an image.'),
    '#options' => $imageStyleOptions,
    '#default_value' => !empty($initialImageStyles) ? $initialImageStyles : [],
    '#size' => 10,
  ];
  $form['initial_image_styles']['#attributes']['class'][] = 'image-style-warmer';
  $form['initial_image_styles']['#attributes']['class'][] = 'image-styles';
  $form['initial_image_styles']['#attributes']['class'][] = 'initial-image-styles';
  $queueImageStyles = $config
    ->get('queue_image_styles');
  $form['queue_image_styles'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Queue image styles'),
    '#description' => $this
      ->t('Select image styles which will be created via queue worker.'),
    '#options' => $imageStyleOptions,
    '#default_value' => !empty($queueImageStyles) ? $queueImageStyles : [],
    '#size' => 10,
  ];
  $form['queue_image_styles']['#attributes']['class'][] = 'image-style-warmer';
  $form['queue_image_styles']['#attributes']['class'][] = 'image-styles';
  $form['queue_image_styles']['#attributes']['class'][] = 'queue-image-styles';

  // Add CSS for better form layout.
  $form['#attached']['library'][] = 'image_style_warmer/image_style_warmer.admin';
  return parent::buildForm($form, $form_state);
}