MaterioSapiSearchForm.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. "v-focus" => "",
  31. // "v-on:select" => "typed",
  32. ],
  33. '#autocomplete_route_name' => 'materio_sapi.search_autocomplete',
  34. ];
  35. $form['searchautocomplete'] = [
  36. '#type' => 'hidden',
  37. '#attributes' => [
  38. "v-model" => "autocomplete"
  39. ],
  40. ];
  41. // $form['submit'] = [
  42. // '#type' => 'submit',
  43. // '#value' => $this->t('Search'),
  44. // '#attributes' => [
  45. // '@click.prevent' => "submit",
  46. // ]
  47. // ];
  48. $form['submit'] = array(
  49. '#type' => 'button',
  50. // '#src' => '',//drupal_get_path('module', 'materio_search_api') . '/images/search.png',
  51. '#value' => t('Search'),
  52. // '#prefix' => '<div class="search-btn-wrapper">',
  53. // '#suffix'=> '</div>',
  54. '#attributes' => [
  55. 'title' => t('Search'),
  56. '@click.prevent' => "submit",
  57. ]
  58. );
  59. return $form;
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function validateForm(array &$form, FormStateInterface $form_state) {
  65. parent::validateForm($form, $form_state);
  66. }
  67. /**
  68. * {@inheritdoc}
  69. */
  70. public function submitForm(array &$form, FormStateInterface $form_state) {
  71. // Display result.
  72. foreach ($form_state->getValues() as $key => $value) {
  73. drupal_set_message($key . ': ' . $value);
  74. }
  75. }
  76. }