FederatedSearchPageBlockForm.php in Search API Federated Solr 8.3
Same filename and directory in other branches
Contains \Drupal\search_api_solr_federated\Form\FederatedSearchPageBlockForm.
Namespace
Drupal\search_api_federated_solr\FormFile
src/Form/FederatedSearchPageBlockForm.phpView source
<?php
namespace Drupal\search_api_federated_solr\Form;
/**
* @file
* Contains \Drupal\search_api_solr_federated\Form\FederatedSearchPageBlockForm.
*/
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\search_api_federated_solr\Utility\Helpers;
/**
* Class FederatedSearchPageForm.
*
* @package Drupal\search_api_federated_solr\Form
*/
class FederatedSearchPageBlockForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'federated_search_page_block_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$renderer = \Drupal::service('renderer');
$app_config = \Drupal::config('search_api_federated_solr.search_app.settings');
$form['#theme'] = 'search_api_federated_solr_block_form';
$form['search'] = [
'#type' => 'search',
'#name' => 'search',
'#title' => $this
->t('Search'),
'#title_display' => 'invisible',
'#size' => 15,
'#default_value' => '',
'#attributes' => [
'title' => $this
->t('Enter the terms you wish to search for.'),
'placeholder' => 'Search',
'autocomplete' => "off",
],
'#provider' => 'search_api_federated_solr',
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Search'),
'#name' => '',
'#provider' => 'search_api_federated_solr',
];
// Send site name as qs param if app is configured to load w/default site.
if ($app_config
->get('facet.site_name.set_default')) {
$site_name = Helpers::getSiteName();
if ($site_name) {
$form['sm_site_name'] = [
'#type' => 'hidden',
'#name' => 'sm_site_name',
'#default_value' => $site_name,
];
}
}
$form['#action'] = \Drupal::urlGenerator()
->generateFromRoute('search_api_federated_solr.search');
$form['#method'] = 'get';
// Ensure that this form's render cache is invalidated when search app
// config is updated.
$renderer
->addCacheableDependency($form, $app_config);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// This form submits to the search page, so processing happens there.
}
}
Classes
Name | Description |
---|---|
FederatedSearchPageBlockForm | Class FederatedSearchPageForm. |