You are here

public function WebformSubmissionFilterForm::buildForm in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Form/WebformSubmissionFilterForm.php \Drupal\webform\Form\WebformSubmissionFilterForm::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 FormInterface::buildForm

File

src/Form/WebformSubmissionFilterForm.php, line 24

Class

WebformSubmissionFilterForm
Provides the webform submission filter form.

Namespace

Drupal\webform\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $search = NULL, $state = NULL, array $state_options = [], $source_entity = NULL, $source_entity_options = []) {
  $form['#attributes'] = [
    'class' => [
      'webform-filter-form',
    ],
  ];
  $form['filter'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Filter submissions'),
    '#open' => TRUE,
    '#attributes' => [
      'class' => [
        'container-inline',
      ],
    ],
  ];
  $form['filter']['search'] = [
    '#type' => 'search',
    '#title' => $this
      ->t('Keyword'),
    '#title_display' => 'invisible',
    '#placeholder' => $this
      ->t('Filter by submitted data and/or notes'),
    '#maxlength' => 128,
    '#size' => 40,
    '#default_value' => $search,
  ];
  if ($source_entity_options) {
    if ($source_entity_options instanceof WebformInterface) {
      $form['filter']['entity'] = [
        '#type' => 'search',
        '#title' => $this
          ->t('Submitted to'),
        '#title_display' => 'invisible',
        '#autocomplete_route_name' => 'entity.webform.results.source_entity.autocomplete',
        '#autocomplete_route_parameters' => [
          'webform' => $source_entity_options
            ->id(),
        ],
        '#placeholder' => $this
          ->t('Enter submitted to…'),
        '#size' => 20,
        '#default_value' => $source_entity,
      ];
    }
    else {
      $form['filter']['entity'] = [
        '#type' => 'select',
        '#title' => $this
          ->t('Submitted to'),
        '#title_display' => 'invisible',
        '#options' => [
          '' => $this
            ->t('Filter by submitted to'),
        ] + $source_entity_options,
        '#default_value' => $source_entity,
      ];
    }
  }
  $form['filter']['state'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('State'),
    '#title_display' => 'invisible',
    '#options' => $state_options,
    '#default_value' => $state,
  ];
  $form['filter']['submit'] = [
    '#type' => 'submit',
    '#button_type' => 'primary',
    '#value' => $this
      ->t('Filter'),
  ];
  if (!empty($search) || !empty($state)) {
    $form['filter']['reset'] = [
      '#type' => 'submit',
      '#submit' => [
        '::resetForm',
      ],
      '#value' => $this
        ->t('Reset'),
    ];
  }
  return $form;
}