You are here

public function ImageZoomOptionsForm::form in Image Zoom 8.3

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Form/ImageZoomOptionsForm.php, line 17

Class

ImageZoomOptionsForm
Class ImageZoomOptionsForm.

Namespace

Drupal\imagezoom\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $imagezoom = $this->entity;
  $image_styles = image_style_options(FALSE);
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $imagezoom
      ->label(),
    '#description' => $this
      ->t("Label for the Image Zoom options profile."),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $imagezoom
      ->id(),
    '#machine_name' => [
      'exists' => '\\Drupal\\imagezoom\\Entity\\ImageZoomOptions::load',
    ],
    '#disabled' => !$imagezoom
      ->isNew(),
  ];
  $form['zoom_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Zoom type'),
    '#options' => [
      'window' => $this
        ->t('Window'),
      'inner' => $this
        ->t('Inner'),
      'lens' => $this
        ->t('Lens'),
    ],
    '#default_value' => $imagezoom
      ->getOption('zoom_type'),
  ];
  $form['display_style'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Image style'),
    '#options' => $image_styles,
    '#empty_option' => $this
      ->t('None (original image)'),
    '#default_value' => $imagezoom
      ->getOption('display_style'),
  ];
  $form['zoom_style'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Zoomed Image style'),
    '#options' => $image_styles,
    '#empty_option' => $this
      ->t('None (original image)'),
    '#default_value' => $imagezoom
      ->getOption('zoom_style'),
  ];
  $form['thumb_style'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Thumbnail image style'),
    '#options' => $image_styles,
    '#empty_option' => $this
      ->t('None (original image)'),
    '#default_value' => $imagezoom
      ->getOption('thumb_style'),
  ];
  $form['disable'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Disable zoom on small screens'),
    '#return_value' => 1,
    '#default_value' => $imagezoom
      ->getOption('disable'),
    '#weight' => 10,
  ];
  $form['disable_width'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Minimum width for zoom to display'),
    '#min' => 0,
    '#states' => [
      'invisible' => [
        ':input[name="disable"]' => [
          'checked' => FALSE,
        ],
      ],
    ],
    '#default_value' => $imagezoom
      ->getOption('disable_width'),
    '#weight' => 10,
  ];
  return $form;
}