MaterioSapiSearchForm.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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" => "keys",
  30. // "v-on:select" => "typed",
  31. ],
  32. '#autocomplete_route_name' => 'materio_sapi.search_autocomplete',
  33. ];
  34. $form['searchautocomplete'] = [
  35. '#type' => 'hidden',
  36. '#attributes' => [
  37. "v-model" => "autocomplete"
  38. ],
  39. ];
  40. $form['submit'] = [
  41. '#type' => 'submit',
  42. '#value' => $this->t('Search'),
  43. '#attributes' => [
  44. '@click.prevent' => "submit",
  45. ]
  46. ];
  47. return $form;
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function validateForm(array &$form, FormStateInterface $form_state) {
  53. parent::validateForm($form, $form_state);
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function submitForm(array &$form, FormStateInterface $form_state) {
  59. // Display result.
  60. foreach ($form_state->getValues() as $key => $value) {
  61. drupal_set_message($key . ': ' . $value);
  62. }
  63. }
  64. }