Compare commits

...

25 Commits
d9 ... 2.x

Author SHA1 Message Date
Paul Pound adac1fca75 remove non upei guest links for off campus users 3 weeks ago
Paul Pound 3c6a627b10 updated body substring code 7 months ago
Paul Pound 222a8f83d0 updated eds js files to get profile from drupal settings 8 months ago
Paul Pound d965873e4c enclose bestbet searches in quotes if it isnt already 10 months ago
Paul Pound a5202d3719 limit bestbet searchs to title_1 field 10 months ago
Paul Pound 29d6951b42 add encoding for eds articles query string 1 year ago
Paul Pound f01db8fe1e adding no cache to the search route 1 year ago
Paul Pound 6145608666 better query checking before redirect 1 year ago
Paul Pound 9a8ac932a1 removed vim command string 1 year ago
Paul Pound 48ec54f7ee no block caching for anonymous 1 year ago
Paul Pound 32166bdddd use link field title instead of node title for bestbet results 1 year ago
Paul Pound 2757e95490 fix link to all solr results when query in quotes 1 year ago
Paul Pound d76a9d875a less encoding decoding 1 year ago
Paul Pound 629ab184dc match the d7 versions search results by not escapting brackets 1 year ago
Paul Pound 0b52c19cd3 no guest access 1 year ago
Paul Pound 3dd4c3f665 hide the bestbet bento if there are no results 2 years ago
Paul Pound d8405b0b83 fixed a double quote typo in twig template 2 years ago
Paul Pound c4318e1f90 added some divs with classes to mimic old site 2 years ago
Paul Pound 3a1a8db0ff add alternate path for use case of users embedding form elements directly in pages 2 years ago
ppound f702f1bed2 updates to solr results for drupal10 2 years ago
ppound abc328ebd9 leave block caching at default for now 2 years ago
ppound df0438b164 disabled the block caching 2 years ago
ppound d4aad3318f updates for drupal 10 2 years ago
ppound 57ba9f413c corrected settings name 3 years ago
ppound 59b5d8657d added composer json file 3 years ago
  1. 25
      composer.json
  2. 12
      modules/roblib_search_eds/js/eds_results_article.js
  3. 12
      modules/roblib_search_eds/js/eds_results_book.js
  4. 3
      modules/roblib_search_eds/roblib_search_eds.info.yml
  5. 2
      modules/roblib_search_eds/src/Controller/RoblibSearchEdsController.php
  6. 5
      modules/roblib_search_eds/src/Lib/EBSCOAPI.php
  7. 5
      modules/roblib_search_eds/src/Lib/EBSCOConnector.php
  8. 12
      modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsArticles.php
  9. 12
      modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsBooks.php
  10. 4
      modules/roblib_search_eds/templates/roblib-search-eds-articles.html.twig
  11. 3
      modules/roblib_search_eds/templates/roblib-search-eds-books.html.twig
  12. 3
      modules/solr_site/README.md
  13. 1
      modules/solr_site/js/solr_site_bestbet.js
  14. 7
      modules/solr_site/js/solr_site_results.js
  15. 2
      modules/solr_site/roblib_search_solr_site.info.yml
  16. 26
      modules/solr_site/src/Controller/RoblibSearchSolrsiteController.php
  17. 4
      modules/solr_site/src/Form/SolrsiteSettingsForm.php
  18. 16
      modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteBestbet.php
  19. 16
      modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteGeneral.php
  20. 4
      modules/solr_site/templates/roblib-search-solr-site-bestbet.html.twig
  21. 4
      modules/solr_site/templates/roblib-search-solr-site-results.html.twig
  22. 8
      roblib_search.info.yml
  23. 2
      roblib_search.routing.yml
  24. 14
      src/Controller/RoblibSearchController.php
  25. 2
      src/Form/RoblibSearchForm.php

25
composer.json

@ -0,0 +1,25 @@
{
"name": "roblib/roblib_search",
"description": "Searches various enpoints and displays results from each endpoint.",
"type": "drupal-module",
"license": "GPL-2.0-or-later",
"homepage": "https://git.library.upei.ca/Code/upei_roblib_search",
"authors": [
{
"name": "Paul Pound",
"role": "Maintainer"
}
],
"support": {
"issues": "https://git.library.upei.ca/Code/upei_roblib_search/issues",
"source": "https://git.library.upei.ca/Code/upei_roblib_search"
},
"repositories": [
{
"type": "git",
"url": "git@git.library.upei.ca:Code/upei_roblib_search.git",
"reference": "2.x"
}
],
"require": { }
}

12
modules/roblib_search_eds/js/eds_results_article.js

@ -3,7 +3,7 @@ Drupal.behaviors.roblib_search_eds_articles = {
if (context == document) {
$query = drupalSettings.path.currentPath.replace('roblib_search/', '');
$url = settings.eds_article_search_url + $query;
profile = settings.eds_article_profile;
article_profile = settings.eds_article_profile;
proxy_url = "https://proxy.library.upei.ca/login?url=";
jQuery.getJSON($url, function (data) {
var items = [];
@ -25,7 +25,7 @@ Drupal.behaviors.roblib_search_eds_articles = {
queries.push(query.query);
})
var query_str = encodeURI(data.queries[0].query);
var href_str = 'https://search.ebscohost.com/login.aspx?direct=true&site=eds-live&scope=site&type=1&custid=uprince&groupid=main&profile=eds&mode=bool&lang=en&bquery=';
var href_str = 'https://search.ebscohost.com/login.aspx?direct=true&site=eds-live&scope=site&type=1&custid=uprince&groupid=main&profid=' + article_profile + '&mode=bool&lang=en&bquery=';
jQuery.each(data.documents, function (key, val) {
id = 'roblib-search-eds-article-' + counter;
divs[counter++] = id;
@ -74,10 +74,10 @@ Drupal.behaviors.roblib_search_eds_articles = {
}
var non_upei_link = '';
var upei_link = '<a href="' + proxy_url + href_str + query_str + '" id="eds-article-see-all-results">SEE ALL (' + data.recordCount + ')</a> ';
if (!data.is_local_ip) {
non_upei_link = '<a href="' + href_str + query_str + '&authtype=ip,guest" id="eds-article-non-upei-see_all_results">[Non-UPEI]</a>';
upei_link = upei_link + non_upei_link;
}
// if (!data.is_local_ip) {
// non_upei_link = '<a href="' + href_str + query_str + '&authtype=ip,guest" id="eds-article-non-upei-see_all_results">[Non-UPEI]</a>';
// upei_link = upei_link + non_upei_link;
// }
jQuery('#roblib-search-eds-article-more').empty().append(upei_link);
jQuery('#roblib-eds-articles-more-results').empty().append(upei_link);
jQuery('#roblib-eds-articles-toc').empty().append('<a href="' + proxy_url + href_str + query_str + '" id="eds-article-see-all-results-toc">Articles (' + data.recordCount + ')</a>');

12
modules/roblib_search_eds/js/eds_results_book.js

@ -3,7 +3,7 @@ Drupal.behaviors.roblib_search_eds = {
if (context == document) {
$query = drupalSettings.path.currentPath.replace('roblib_search/', '');
$url = settings.eds_book_search_url + $query;
profile = settings.eds_book_profile;
book_profile = settings.eds_book_profile;
proxy_url = "https://proxy.library.upei.ca/login?url=";
jQuery.getJSON($url, function (data) {
var items = [];
@ -25,7 +25,7 @@ Drupal.behaviors.roblib_search_eds = {
queries.push(query.query);
})
var query_str = encodeURI(data.queries[0].query);
var href_str = 'https://search.ebscohost.com/login.aspx?direct=true&site=eds-live&scope=site&type=1&custid=uprince&groupid=main&profid=lite&mode=bool&lang=en&bquery=';
var href_str = 'https://search.ebscohost.com/login.aspx?direct=true&site=eds-live&scope=site&type=1&custid=uprince&groupid=main&profid='+ book_profile + '&mode=bool&lang=en&bquery=';
jQuery.each(data.documents, function (key, val) {
id = 'roblib-search-eds-' + counter;
@ -76,10 +76,10 @@ Drupal.behaviors.roblib_search_eds = {
}
var non_upei_link = '';
var upei_link = '<a href="' + proxy_url + href_str + query_str + '" id="eds-see-all-results">SEE ALL (' + data.recordCount + ')</a> ';
if (!data.is_local_ip) {
non_upei_link = '<a href="' + href_str + query_str + '&authtype=ip,guest" id="eds-non-upei-see_all_results">[Non-UPEI]</a>';
upei_link = upei_link + non_upei_link;
}
// if (!data.is_local_ip) {
// non_upei_link = '<a href="' + href_str + query_str + '&authtype=ip,guest" id="eds-non-upei-see_all_results">[Non-UPEI]</a>';
// upei_link = upei_link + non_upei_link;
// }
jQuery('#roblib-search-eds-more').empty().append(upei_link);
jQuery('#roblib-eds-books-more-results').empty().append(upei_link);
jQuery('#roblib-eds-books-toc').empty().append('<a href="' + proxy_url + href_str + query_str + '" id="eds-see-all-results-toc">Books (' + data.recordCount + ')</a>');

3
modules/roblib_search_eds/roblib_search_eds.info.yml

@ -3,7 +3,6 @@ type: module
configure: roblib_search_eds.settings
description: Implements the Roblib Search EDS book and article results
package: Roblib Search
core_version_requirement: ^8.9 || ^9
core_version_requirement: ^9 || ^10
dependancies:
- roblib_search
- ebsco

2
modules/roblib_search_eds/src/Controller/RoblibSearchEdsController.php

@ -63,7 +63,7 @@ class RoblibSearchEdsController extends ControllerBase {
$search = array('lookfor' => $query, 'type' => 'ALLFields', 'index' => 'AllFields', 'q' => 'ebsco/results', 'op' => 'Search');
$eds_api = new EBSCOAPI($eds_config);
$is_local_ip = $eds_api->connector()->isGuestIPAddress($_SERVER["REMOTE_ADDR"]);
$eds_api->isGuest(!$is_local_ip);
$eds_api->isGuest(FALSE);
$output = $eds_api->apiSearch($search, $filters, 1, $number_per_page);
$output['is_local_ip'] = $is_local_ip;

5
modules/roblib_search_eds/src/Lib/EBSCOAPI.php

@ -459,7 +459,10 @@ class EBSCOAPI {
$type = isset($search['index']) && !empty($search['index']) ? $search['index'] : 'AllFields';
// Escape some characters from lookfor term.
$term = str_replace(array(',', ':', '(', ')'), array('\,', '\:', '\(', '\)'), $lookfor);
//$term = str_replace(array(',', ':', '(', ')'), array('\,', '\:', '\(', '\)'), $lookfor);
// The below version of the above matches the drupal 7 searches but the above may give less but better results
// and be worth testing down the road.
$term = str_replace(array(',', ':'), array('\,', '\:'), $lookfor);
// Replace multiple consecutive empty spaces with one empty space.
$term = preg_replace("/\s+/", ' ', $term);

5
modules/roblib_search_eds/src/Lib/EBSCOConnector.php

@ -214,7 +214,7 @@ class EBSCOConnector {
$this->autoComplete = $config['autocomplete'];
$this->orgId = $config['organization'];
$this->local_ip_address = $config['local_ip_address'];
$this->isGuest = (\Drupal::currentUser()->isAuthenticated() || $this->isGuestIPAddress($_SERVER["REMOTE_ADDR"])) ? 'n' : 'y';
$this->isGuest = 'n';
$this->logAPIRequests = ($config['log'] == 1);
}
@ -432,6 +432,9 @@ class EBSCOConnector {
$xml = FALSE;
$return = FALSE;
$data = NULL;
if(!is_array($headers)){
$headers = [];
}
// Add compression in case its not there.
array_push($headers, 'Content-Type: text/xml');

12
modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsArticles.php

@ -38,4 +38,16 @@ class RoblibSearchEdsArticles extends BlockBase {
],
];
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
// Reading dynamic content from external source so no caching.
if (\Drupal::currentUser()->isAnonymous()) {
// Anonymous user...
return 0;
}
}
}

12
modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsBooks.php

@ -39,4 +39,16 @@ class RoblibSearchEdsBooks extends BlockBase {
];
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
// Reading dynamic content from external source so no caching.
if (\Drupal::currentUser()->isAnonymous()) {
// Anonymous user...
return 0;
}
}
}

4
modules/roblib_search_eds/templates/roblib-search-eds-articles.html.twig

@ -1,10 +1,12 @@
<div class="panel-pane pane-block pane-roblib-search-eds-roblib-search-eds-results pane-roblib-search-eds">
<div class="roblib-search-header roblib-search-eds-articles-header"><h3>Articles</h3></div>
<div class ="roblib-search-more" id="roblib-search-eds-article-more"></div>
<div class ="roblib-search-content eds-article" id="roblib-search-content-eds-articles">
<img src="{{ spinner_path }}"/>
</div>
<div id="roblib-eds-articles-more-results" class="roblib-eds-more-button button"></div>
<div id="roblib-eds-articles-toc" class="roblib-bento-toc moveme-please"></div>
</div>

3
modules/roblib_search_eds/templates/roblib-search-eds-books.html.twig

@ -1,7 +1,10 @@
<div class="panel-pane pane-block pane-roblib-search-eds-roblib-search-eds-results pane-roblib-search-eds">
<div class="roblib-search-header roblib-search-eds-media-header"><h3>Books</h3></div>
<div class ="roblib-search-more" id="roblib-search-eds-more"></div>
<div class ="roblib-search-content eds" id="roblib-search-content-eds">
<img src="{{ spinner_path }}"/>
</div>
<div id="roblib-eds-books-more-results" class="roblib-eds-more-button button"></div>
<div id="roblib-eds-books-toc" class="roblib-bento-toc moveme-please"></div>
</div>

3
modules/solr_site/README.md

@ -18,6 +18,9 @@ Requires roblib_search module. Also assumes Solr Search API is installed and
the index has fields for body, body summary, type, rendered_item and
search_api_url
For the BestBet block we also need a content type of bestbet with title, body
link fields (field_link). The field_link will also have to be added to the
solr index.
## Configuration

1
modules/solr_site/js/solr_site_bestbet.js

@ -10,6 +10,7 @@ Drupal.behaviors.roblib_search_solr_bestbet_results = {
if (total_found < 1) {
jQuery('#' + 'roblib-search-content-solr-site-bestbet').empty().append('No Results');
jQuery('.' + 'pane-roblib-search-solr-site-roblib-search-solr-site-bestbet').hide();
jQuery('.' + 'pane-roblib-search-solr-site-roblib-search-solr-site-' . solrType).hide();
} else {
jQuery('#' + 'roblib-search-content-solr-site-bestbet').empty();

7
modules/solr_site/js/solr_site_results.js

@ -1,7 +1,8 @@
Drupal.behaviors.roblib_search_solr_site_results = {
attach: function (context, settings) {
if (context == document) {
query = drupalSettings.path.currentPath.replace('roblib_search/', '');
unencoded_query = drupalSettings.path.currentPath.replace('roblib_search/', '');
query = encodeURIComponent(unencoded_query);
solrUrl = settings.solr_site_search_url + query;
baseUrl = settings.solr_site_base_url + query;
jQuery.getJSON(baseUrl, function (data) {
@ -28,9 +29,9 @@ Drupal.behaviors.roblib_search_solr_site_results = {
jQuery('#' + 'roblib-search-content-solr-site-results').empty().append(items.join(''));
}
if (total_found > 0) {
results_url = '<a href="' + solrUrl + '">see all results ('
results_url = '<a href=\'' + solrUrl + '\'>see all results ('
+ total_found + ') </a>';
move_me_div_url = '<a href="' + solrUrl + '">Library Site ('
move_me_div_url = '<a href=\'' + solrUrl + '\'>Library Site ('
+ total_found + ') </a>';
jQuery('#' + 'roblib-search-solr-site-results-more').empty().append(results_url);
jQuery('#' + 'roblib-solr-more-results-results').empty().append(results_url);

2
modules/solr_site/roblib_search_solr_site.info.yml

@ -3,6 +3,6 @@ type: module
configure: roblib_search_solr_site.settings
description: Implements the Roblib Search for local Solr site bento results
package: Roblib Search
core_version_requirement: ^8.9 || ^9
core_version_requirement: ^9 || ^10
dependancies:
- roblib_search

26
modules/solr_site/src/Controller/RoblibSearchSolrsiteController.php

@ -48,9 +48,9 @@ class RoblibSearchSolrsiteController extends ControllerBase {
return '';
}
}
$queryString = urlencode($queryString);
//$queryString = urlencode($queryString);
// TODO make the index configurable.
$index = \Drupal\search_api\Entity\Index::load('default_solr_index');
$index = \Drupal\search_api\Entity\Index::load('library');
$query = $index->query();
// Change the parse mode for the search.
@ -65,7 +65,13 @@ class RoblibSearchSolrsiteController extends ControllerBase {
$query->keys($queryString);
if ($solr_type == 'BestBet') {
$query->addCondition('type', 'bestbet');
$query->addCondition('type', 'bestbet', '=');
$query->setFulltextFields(['title_1']);
if(str_starts_with($queryString, '"')) {
$query->keys($queryString);
} else {
$query->keys('"'.$queryString.'"');
}
} else {
$query->addCondition('type', 'bestbet', '<>');
}
@ -81,13 +87,17 @@ class RoblibSearchSolrsiteController extends ControllerBase {
$output['results'] = [];
foreach ($results as $result) {
$id = $result->getId();
$titles = $result->getField('title')->getValues();
$output['results'][$id]['title'] = $titles[0]->getText();
$title = $result->getField('title');
if(empty($title)){
break;
}
$titles = $title->getValues();
$output['results'][$id]['title'] = reset($titles);
$body = $result->getField('body')->getValues();
if (!empty($body)) {
$bodyOutput = strip_tags($body[0]->getText());
if (strlen($bodyOutput) > 500) {
$bodyOutput = substr($bodyOutput, 0, 500) . '...';
$bodyOutput = substr($bodyOutput, 0, 499) . '...';
}
}
$output['results'][$id]['body'] = empty($bodyOutput) ? '' : $bodyOutput;
@ -99,6 +109,10 @@ class RoblibSearchSolrsiteController extends ControllerBase {
$output['results'][$id]['type'] = reset($type);
$urls = $result->getField('url')->getValues();
$output['results'][$id]['url'] = reset($urls);
if ($solr_type == 'BestBet') {
$entity = $result->getOriginalObject()->getValue();
$output['results'][$id]['title'] = $entity->field_link->first()->title;
}
$links = $result->getField('field_link')->getValues();
$output['results'][$id]['field_link'] = empty($links) ? '' : $links;
}

4
modules/solr_site/src/Form/SolrsiteSettingsForm.php

@ -23,7 +23,7 @@ class SolrsiteSettingsForm extends FormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = \Drupal::config('roblib_search_solr.settings');
$config = \Drupal::config('roblib_search_solr_site.settings');
$form['solr_site_url'] = array(
'#type' => 'textfield',
@ -59,7 +59,7 @@ class SolrsiteSettingsForm extends FormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = \Drupal::configFactory()->getEditable('roblib_search_solr.settings');
$config = \Drupal::configFactory()->getEditable('roblib_search_solr_site.settings');
$config->set('solr_site_url', $form_state->getValue('solr_site_url'))->save();
$config->set('solr_site_num_results', $form_state->getValue('solr_site_num_results'))->save();
}

16
modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteBestbet.php

@ -19,7 +19,7 @@ class RoblibSearchSolrSiteBestbet extends BlockBase {
* {@inheritdoc}
*/
public function build() {
$search_url = \Drupal::config('roblib_search_solr.settings')
$search_url = \Drupal::config('roblib_search_solr_site.settings')
->get('solr_site_url');
$settings = [
'solr_site_search_url' => $search_url,
@ -37,7 +37,15 @@ class RoblibSearchSolrSiteBestbet extends BlockBase {
];
}
/*public function getCacheMaxAge() {
return 1;
}*/
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
// Reading dynamic content from external source so no caching.
if (\Drupal::currentUser()->isAnonymous()) {
// Anonymous user...
return 0;
}
}
}

16
modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteGeneral.php

@ -19,12 +19,13 @@ class RoblibSearchSolrsiteGeneral extends BlockBase {
* {@inheritdoc}
*/
public function build() {
$search_url = \Drupal::config('roblib_search_solr.settings')
$search_url = \Drupal::config('roblib_search_solr_site.settings')
->get('solr_site_url');
$settings = [
'solr_site_search_url' => $search_url,
'solr_site_base_url' => '/roblib_search/solr_site/general/',
'solr_type' => 'results',
'solr_site_search_url' => $search_url,
];
return [
'#theme' => 'roblib_search_solr_site_results',
@ -38,8 +39,15 @@ class RoblibSearchSolrsiteGeneral extends BlockBase {
];
}
/*public function getCacheMaxAge() {
return 1;
}*/
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
// Reading dynamic content from external source so no caching.
if (\Drupal::currentUser()->isAnonymous()) {
// Anonymous user...
return 0;
}
}
}

4
modules/solr_site/templates/roblib-search-solr-site-bestbet.html.twig

@ -1,4 +1,5 @@
<div class="panel-pane pane-block pane-roblib-search-solr-site-roblib-search-solr-site-bestbet pane-roblib-search-solr-site">
<div class="roblib-search-header roblib-search-solr-bestbet-header" id="roblib-search-solr-site-bestbet-title"><h3>Best Bet</h3></div>
<div class ="roblib-search-more" id="roblib-search-solr-site-{{ solr_type }}-more"></div>
<div class ="roblib-search-content solr-site-{{ solr_type }}" id="roblib-search-content-solr-site-{{ solr_type }}">
<img src="{{ spinner_path }}"/>
@ -6,3 +7,4 @@
<div id="roblib-solr-more-results-{{ solr_type }}" class="roblib-solr-more-button "></div>
<div id="roblib-solr-search-toc-{{ solr_type }}" class="roblib-bento-toc moveme-please"></div>
</div>

4
modules/solr_site/templates/roblib-search-solr-site-results.html.twig

@ -1,4 +1,5 @@
<div class="panel-pane pane-block pane-roblib-search-solr-site-roblib-search-solr-site-results pane-roblib-search-solr-site">
<div class="roblib-search-header roblib-search-solr-results-header"><h3>Library Site</h3></div>
<div class ="roblib-search-more" id="roblib-search-solr-site-{{ solr_type }}-more"></div>
<div class ="roblib-search-content solr-site-{{ solr_type }}" id="roblib-search-content-solr-site-{{ solr_type }}">
<img src="{{ spinner_path }}"/>
@ -6,3 +7,4 @@
<div id="roblib-solr-more-results-{{ solr_type }}" class="roblib-solr-more-button "></div>
<div id="roblib-solr-search-toc-{{ solr_type }}" class="roblib-bento-toc moveme-please"></div>
</div>

8
roblib_search.info.yml

@ -1,10 +1,10 @@
name: Roblib Search
type: module
core_version_requirement: ^8.9 || ^9
core_version_requirement: ^9 || ^10
configure: roblib_search.settings
description: Provides a search form and fires a hook when the search is submitted. Other modules should implement the search functionality by implementing the correct hooks.
package: Roblib Search
dependancies:
- apachesolr_access
- views_ui
- message
- drupal:views_ui
- drupal:message

2
roblib_search.routing.yml

@ -12,5 +12,7 @@ roblib_search.landing_page:
_controller: '\Drupal\roblib_search\Controller\RoblibSearchController::searchResults'
_title: 'Roblib Search Landing Page'
query: '[a-zA-Z\s]+'
options:
no_cache: 'TRUE'
requirements:
_permission: 'access content'

14
src/Controller/RoblibSearchController.php

@ -3,6 +3,9 @@
namespace Drupal\roblib_search\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Component\Utility\Html;
/**
* Controller for d3 graphs.
@ -16,6 +19,17 @@ class RoblibSearchController extends ControllerBase {
* A renderable array.
*/
public function searchResults($query = NULL) {
if ($query = $_GET['roblib_query']) {
$query = str_replace('/', ' ',$query);
$query = trim(Html::decodeEntities($query));
if(empty($query)) {
\Drupal::messenger()->addMessage($this->t('Please Enter a valid search string.'));
$url = Url::fromRoute('roblib_search.landing_page');
} else {
$url = Url::fromRoute('roblib_search.landing_page', ['query' => $query]);
}
return new RedirectResponse($url->toString());
}
return [
'#theme' => 'roblib_search_results',
'#query' => $query,

2
src/Form/RoblibSearchForm.php

@ -67,7 +67,7 @@ class RoblibSearchForm extends FormBase{
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$search_string = $form_state->getValue('roblib_search_simple_search_query');
$search_string = Html::escape($search_string);
//$search_string = Html::escape($search_string);
$message = Message::create(['template' => 'roblib_search_message_template',
'uid' => \Drupal::currentUser()->id()]);
$message->set('field_ip_address', \Drupal::request()->getClientIp());

Loading…
Cancel
Save