SearchController.php in Search API Federated Solr 8
File
src/Controller/SearchController.php
View source
<?php
namespace Drupal\search_api_federated_solr\Controller;
use Drupal\Core\Controller\ControllerBase;
class SearchController extends ControllerBase {
public function searchPage() {
$renderer = \Drupal::service('renderer');
$config = \Drupal::configFactory()
->getEditable('search_api_federated_solr.search_app.settings');
$index_config = \Drupal::config('search_api.index.' . $config
->get('index.id'));
$federated_search_app_config = [];
$federated_search_app_config['url'] = $config
->get('index.server_url');
$federated_search_app_config['userpass'] = base64_encode($config
->get('index.username') . ':' . $config
->get('index.password'));
$site_name_property = $index_config
->get('field_settings.site_name.configuration.site_name');
$config
->set('index.has_site_name_property', $site_name_property ? TRUE : FALSE);
$set_default_site = $config
->get('facet.site_name.set_default');
if ($set_default_site && !$site_name_property) {
$config
->set('facet.site_name.set_default', 0);
}
if ($search_prompt = $config
->get('content.search_prompt')) {
$federated_search_app_config['searchPrompt'] = $search_prompt;
}
if ($no_results = $config
->get('content.no_results')) {
$federated_search_app_config['noResults'] = $no_results;
}
if ($show_empty_search_results = $config
->get('content.show_empty_search_results')) {
$federated_search_app_config['showEmptySearchResults'] = $show_empty_search_results;
}
if ($rows = $config
->get('results.rows')) {
$federated_search_app_config['rows'] = intval($rows);
}
if ($pagination_buttons = $config
->get('pagination.buttons')) {
$federated_search_app_config['paginationButtons'] = intval($pagination_buttons);
}
if ($page_title = $config
->get('page_title')) {
$federated_search_app_config['pageTitle'] = $page_title;
}
$element = [
'#theme' => 'search_app',
'#federated_search_app_config' => $federated_search_app_config,
'#attached' => [
'library' => [
'search_api_federated_solr/search',
],
],
];
$renderer
->addCacheableDependency($element, $config);
$renderer
->addCacheableDependency($element, $index_config);
return $element;
}
}