MaterioSapiSearchForm.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Drupal\materio_sapi\Form;
  3. use Drupal\Core\Form\FormBase;
  4. use Drupal\Core\Form\FormStateInterface;
  5. /**
  6. * Class MaterioSapiSearchForm.
  7. */
  8. class MaterioSapiSearchForm extends FormBase {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function getFormId() {
  13. return 'materio_sapi_search_form';
  14. }
  15. /**
  16. * {@inheritdoc}
  17. */
  18. public function buildForm(array $form, FormStateInterface $form_state) {
  19. $form['search'] = [
  20. '#type' => 'textfield',
  21. // '#title' => $this->t('Search'),
  22. '#maxlength' => 64,
  23. '#size' => 25,
  24. '#weight' => '0',
  25. '#attributes' => [
  26. "placeholder" => $this->t('Search'),
  27. "@keyup" => "keyup",
  28. "@keyup.enter" => "submit",
  29. "v-model" => "typed"
  30. ],
  31. '#autocomplete_route_name' => 'materio_sapi.search_autocomplete',
  32. ];
  33. $form['submit'] = [
  34. '#type' => 'submit',
  35. '#value' => $this->t('Search'),
  36. '#attributes' => [
  37. '@click.prevent' => "submit",
  38. ]
  39. ];
  40. return $form;
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function validateForm(array &$form, FormStateInterface $form_state) {
  46. parent::validateForm($form, $form_state);
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function submitForm(array &$form, FormStateInterface $form_state) {
  52. // Display result.
  53. foreach ($form_state->getValues() as $key => $value) {
  54. drupal_set_message($key . ': ' . $value);
  55. }
  56. }
  57. }