You are here

public function WebformImageSelect::form in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_image_select/src/Plugin/WebformElement/WebformImageSelect.php \Drupal\webform_image_select\Plugin\WebformElement\WebformImageSelect::form()

Gets the actual configuration webform array to be built.

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 An associative array contain the element's configuration webform without any default values.

Overrides Select::form

File

modules/webform_image_select/src/Plugin/WebformElement/WebformImageSelect.php, line 247

Class

WebformImageSelect
Provides a 'image_select' element.

Namespace

Drupal\webform_image_select\Plugin\WebformElement

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $form['options']['#title'] = $this
    ->t('Image options');
  $form['options']['images'] = [
    '#title' => $this
      ->t('Images'),
    '#type' => 'webform_image_select_element_images',
    '#weight' => -10,
  ];
  $form['options']['images_randomize'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Randomize images'),
    '#description' => $this
      ->t('Randomizes the order of the images when they are displayed in the webform'),
    '#return_value' => TRUE,
  ];
  $form['options']['show_label'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show labels'),
    '#description' => $this
      ->t('If checked, the image text will be displayed below each image.'),
    '#return_value' => TRUE,
  ];
  $form['options']['filter'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Include filter by label'),
    '#description' => $this
      ->t('If checked, users will be able search/filter images by their labels.'),
    '#return_value' => TRUE,
    '#states' => [
      'visible' => [
        ':input[name="properties[show_label]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['options']['filter_container'] = [
    '#type' => 'container',
    '#attributes' => [
      'data-webform-states-no-clear' => TRUE,
    ],
    '#states' => [
      'visible' => [
        ':input[name="properties[filter]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['options']['filter_container']['filter__placeholder'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Filter placeholder label'),
  ];
  $form['options']['filter_container']['filter__singlular'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Filter single item label'),
  ];
  $form['options']['filter_container']['filter__plural'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Filter plural items label'),
  ];
  $form['options']['filter_container']['filter__no_results'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Filter no results label'),
  ];
  return $form;
}