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