public function WebformOptionsFilterForm::buildForm in Webform 8.5
Same name and namespace in other branches
- 6.x src/Form/WebformOptionsFilterForm.php \Drupal\webform\Form\WebformOptionsFilterForm::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/ WebformOptionsFilterForm.php, line 23
Class
- WebformOptionsFilterForm
- Provides the webform options filter form.
Namespace
Drupal\webform\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $search = NULL, $category = NULL, array $categories = []) {
$form['#attributes'] = [
'class' => [
'webform-filter-form',
],
];
$form['filter'] = [
'#type' => 'details',
'#title' => $this
->t('Filter options'),
'#open' => TRUE,
'#attributes' => [
'class' => [
'container-inline',
],
],
];
$form['filter']['search'] = [
'#type' => 'search',
'#title' => $this
->t('Keyword'),
'#title_display' => 'invisible',
'#autocomplete_route_name' => 'entity.webform_options.autocomplete',
'#placeholder' => $this
->t('Filter by title or options'),
'#size' => 45,
'#default_value' => $search,
];
$form['filter']['category'] = [
'#type' => 'select',
'#title' => $this
->t('Category'),
'#title_display' => 'invisible',
'#options' => $categories,
'#empty_option' => $category ? $this
->t('Show all options') : $this
->t('Filter by category'),
'#default_value' => $category,
];
$form['filter']['submit'] = [
'#type' => 'submit',
'#button_type' => 'primary',
'#value' => $this
->t('Filter'),
];
if (!empty($search) || !empty($category)) {
$form['filter']['reset'] = [
'#type' => 'submit',
'#submit' => [
'::resetForm',
],
'#value' => $this
->t('Reset'),
];
}
return $form;
}