SearchBoxForm.php in Panopoly Search 8.2
File
src/Form/SearchBoxForm.php
View source
<?php
namespace Drupal\panopoly_search\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SearchBoxForm extends FormBase {
protected $logger;
public function __construct(LoggerInterface $logger) {
$this->logger = $logger;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('logger.factory')
->get('panopoly_search'));
}
public function getFormId() {
return 'panopoly_search_box_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$search_page_route = panopoly_search_page_route();
if (empty($search_page_route)) {
$form['message'] = [
'#markup' => $this
->t('Search is currently disabled'),
];
return $form;
}
$form['#action'] = Url::fromRoute($search_page_route)
->toString();
$form['#method'] = 'get';
$form['keys'] = [
'#type' => 'search',
'#title' => $this
->t('Enter your keywords'),
'#size' => 15,
'#default_value' => '',
'#attributes' => [
'title' => $this
->t('Enter the terms you wish to search for.'),
],
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Search'),
'#name' => '',
'#attributes' => [
'class' => [
'search-form__submit',
],
],
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
}
}