You are here

public function JsonApiImageStylesAdminForm::buildForm in JSON:API Image Styles 2.0.x

Same name and namespace in other branches
  1. 8 src/Form/JsonApiImageStylesAdminForm.php \Drupal\jsonapi_image_styles\Form\JsonApiImageStylesAdminForm::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/JsonApiImageStylesAdminForm.php, line 63

Class

JsonApiImageStylesAdminForm
Provides an admin form for modifying the module configuration.

Namespace

Drupal\jsonapi_image_styles\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) : array {
  $config = $this
    ->config('jsonapi_image_styles.settings');
  $options = [];
  $styles = $this->entityTypeManager
    ->getStorage('image_style')
    ->loadMultiple();
  foreach ($styles as $name => $style) {
    $options[$name] = $style
      ->label();
  }
  $form['image_styles'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Image styles'),
    '#description' => $this
      ->t('Select image styles to expose for JSON:API. If none are selected, all styles are exposed.'),
    '#options' => $options,
    '#default_value' => is_array($config
      ->get('image_styles')) ? $config
      ->get('image_styles') : [],
  ];
  return parent::buildForm($form, $form_state);
}