SearchForm.php in Simple Google Custom Search Engine 8
File
src/Form/SearchForm.php
View source
<?php
namespace Drupal\simple_gse_search\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class SearchForm extends FormBase {
public function getFormId() {
return 'simple_gse_search_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['s'] = [
'#type' => 'textfield',
'#title' => t('Search'),
'#default_value' => $form_state
->getValue('s', $this
->getRequest()->query
->get('s', '')),
'#attributes' => [
'placeholder' => $this
->t('Search site...'),
'class' => [
'SearchForm-input',
],
],
'#theme_wrappers' => [],
'#size' => NULL,
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('go'),
'#attributes' => [
'class' => [
'SearchForm-submit',
],
],
];
$form['#attributes'] = [
'class' => [
'SearchForm',
],
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state
->setRedirectUrl(Url::fromRoute('simple_gse_search.search_page', [], [
'query' => [
's' => $form_state
->getValue('s'),
],
]));
}
}
Classes
Name |
Description |
SearchForm |
Defines a form for performing a simple redirect to display search results. |