MaterioSapiSearchForm.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. ],
  28. '#autocomplete_route_name' => 'materio_sapi.search_autocomplete',
  29. ];
  30. $form['submit'] = [
  31. '#type' => 'submit',
  32. '#value' => $this->t('Search'),
  33. ];
  34. return $form;
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function validateForm(array &$form, FormStateInterface $form_state) {
  40. parent::validateForm($form, $form_state);
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function submitForm(array &$form, FormStateInterface $form_state) {
  46. // Display result.
  47. foreach ($form_state->getValues() as $key => $value) {
  48. drupal_set_message($key . ': ' . $value);
  49. }
  50. }
  51. }