Compare commits

..

No commits in common. '2.x' and 'd9' have entirely different histories.
2.x ... d9

  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. 5
      modules/roblib_search_eds/roblib_search_eds.info.yml
  5. 6
      modules/roblib_search_eds/src/Controller/RoblibSearchEdsController.php
  6. 45
      modules/roblib_search_eds/src/Lib/EBSCOAPI.php
  7. 35
      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. 4
      modules/solr_site/roblib_search_solr_site.info.yml
  16. 28
      modules/solr_site/src/Controller/RoblibSearchSolrsiteController.php
  17. 4
      modules/solr_site/src/Form/SolrsiteSettingsForm.php
  18. 18
      modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteBestbet.php
  19. 18
      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. 6
      roblib_search.routing.yml
  24. 14
      src/Controller/RoblibSearchController.php
  25. 6
      src/Form/RoblibSearchForm.php

25
composer.json

@ -1,25 +0,0 @@
{
"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;
article_profile = settings.eds_article_profile;
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&profid=' + article_profile + '&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&profile=eds&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;
book_profile = settings.eds_book_profile;
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='+ book_profile + '&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=lite&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>');

5
modules/roblib_search_eds/roblib_search_eds.info.yml

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

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

@ -16,7 +16,7 @@ class RoblibSearchEdsController extends ControllerBase {
*/
public function articleResults($query = NULL) {
print $this->eds_get_results($query, 'Articles');
exit();
exit();
}
/**
@ -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(FALSE);
$eds_api->isGuest(!$is_local_ip);
$output = $eds_api->apiSearch($search, $filters, 1, $number_per_page);
$output['is_local_ip'] = $is_local_ip;
@ -103,7 +103,7 @@ class RoblibSearchEdsController extends ControllerBase {
$ebsco_config['user'] = $roblib_search_config->get('eds_user');
$ebsco_config['password'] = $roblib_search_config->get('eds_pass');
//get the local ips allowed from ebsco
//TODO move this to a variable
//TODO move this to a variable
$ebsco_config['local_ip_address'] = $roblib_search_config->get('eds_local_ip');
$ebsco_config['profile'] = ($type === 'Books') ? $roblib_search_config->get
('eds_book_profile') : $roblib_search_config->get('eds_article_profile');

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

@ -115,7 +115,7 @@ class EBSCOAPI {
*
* @access public
*/
public function __construct($config) {
public function __construct($config) {
$this->config = $config;
}
@ -128,7 +128,7 @@ class EBSCOAPI {
*
* @access public
*/
public function authenticationToken(){
@ -158,7 +158,7 @@ class EBSCOAPI {
$_SESSION["authenticationTimeout"]= $result['authenticationTimeout'];
$_SESSION['autocompleteUrl'] = $result['autocompleteUrl'];
$_SESSION['autocompleteToken'] = $result['autocompleteToken'];
$_SESSION["autocompleteTokenTimeOut"]= $result['autocompleteTokenTimeOut'];
$_SESSION["autocompleteTokenTimeOut"]= $result['autocompleteTokenTimeOut'];
$_SESSION['autocompleteCustId'] = $result['autocompleteCustId'];
}
@ -168,11 +168,11 @@ class EBSCOAPI {
$_SESSION["authenticationTimeout"]= $result['authenticationTimeout'];
$_SESSION['autocompleteUrl'] = $result['autocompleteUrl'];
$_SESSION['autocompleteToken'] = $result['autocompleteToken'];
$_SESSION["autocompleteTokenTimeOut"]= $result['autocompleteTokenTimeOut'];
$_SESSION["autocompleteTokenTimeOut"]= $result['autocompleteTokenTimeOut'];
$_SESSION['autocompleteCustId'] = $result['autocompleteCustId'];
$result = array(
'authenticationToken' => $token,
@ -459,10 +459,7 @@ class EBSCOAPI {
$type = isset($search['index']) && !empty($search['index']) ? $search['index'] : 'AllFields';
// Escape some characters from lookfor term.
//$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);
$term = str_replace(array(',', ':', '(', ')'), array('\,', '\:', '\(', '\)'), $lookfor);
// Replace multiple consecutive empty spaces with one empty space.
$term = preg_replace("/\s+/", ' ', $term);
@ -595,7 +592,7 @@ class EBSCOAPI {
// Specifies whether or not to include highlighting in the search results.
'highlight' => 'y',
//'includeimagequickview' => $includeimagequickview,
//UPEI commented out
@ -603,7 +600,7 @@ class EBSCOAPI {
//UPEI commented out
//'styles' => $styles,
);
if ($autosuggest == TRUE) {
@ -670,14 +667,14 @@ class EBSCOAPI {
'format' => 'ris',
'styles' => $styles,
);
$result = $this->request('Retrieve', $params);
$result = $this->request('Retrieve', $params);
return $result;
}
public function apiExport($an, $db) {
@ -686,11 +683,11 @@ class EBSCOAPI {
'dbid' => $db,
'format' => 'ris'
);
$result = $this->request('Export', $params);
return $result;
}
public function apiCitationStyles($an, $db, $styles) {
@ -700,14 +697,14 @@ class EBSCOAPI {
'dbid' => $db,
'styles' => $styles
);
$result = $this->request('CitationStyles', $params);
return $result;
}
/**
* Wrapper for info API call.
*
@ -739,7 +736,7 @@ class EBSCOAPI {
return false;
}
}
/**
* Handle a PEAR_Error. Return :

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

@ -214,9 +214,9 @@ class EBSCOConnector {
$this->autoComplete = $config['autocomplete'];
$this->orgId = $config['organization'];
$this->local_ip_address = $config['local_ip_address'];
$this->isGuest = 'n';
$this->isGuest = (\Drupal::currentUser()->isAuthenticated() || $this->isGuestIPAddress($_SERVER["REMOTE_ADDR"])) ? 'n' : 'y';
$this->logAPIRequests = ($config['log'] == 1);
}
/**
@ -381,12 +381,12 @@ class EBSCOConnector {
public function requestCitationStyles($params, $headers) {
$url = self::$end_point . '/CitationStyles';
$responseCitation = $this->request($url, $params, $headers);
$response = $responseCitation->Citations;
return $response;
}
@ -405,7 +405,7 @@ class EBSCOConnector {
public function requestInfo($params, $headers) {
$url = self::$end_point . '/Info';
$response = $this->request($url, $params, $headers);
return $response;
}
@ -432,43 +432,40 @@ 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');
$data=$params;
// Send the request.
$response=null;
try {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_MAXREDIRS, 10 );
curl_setopt($curl, CURLOPT_MAXREDIRS, 10 );
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
switch ($method)
{
case 'GET':
if ($data) { $url = sprintf('%s?%s', $url, http_build_query($data)); }
curl_setopt($curl, CURLOPT_URL, $url);
break;
case 'POST':
if ($data) {
if ($data) {
curl_setopt($curl,CURLOPT_POST, 1);
curl_setopt($curl,CURLOPT_POSTFIELDS, $data);
}
}
break;
case 'DELETE':
if ($data) {
if ($data) {
if (count($headers)>0) {
curl_setopt($curl,CURLOPT_HTTPHEADER, $headers);
}
@ -476,12 +473,12 @@ class EBSCOConnector {
}
break;
}
$response = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
switch ($code) {
case self::HTTP_OK:

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

@ -38,16 +38,4 @@ 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,16 +39,4 @@ 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,12 +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-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,10 +1,7 @@
<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,9 +18,6 @@ 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,7 +10,6 @@ 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,8 +1,7 @@
Drupal.behaviors.roblib_search_solr_site_results = {
attach: function (context, settings) {
if (context == document) {
unencoded_query = drupalSettings.path.currentPath.replace('roblib_search/', '');
query = encodeURIComponent(unencoded_query);
query = drupalSettings.path.currentPath.replace('roblib_search/', '');
solrUrl = settings.solr_site_search_url + query;
baseUrl = settings.solr_site_base_url + query;
jQuery.getJSON(baseUrl, function (data) {
@ -29,9 +28,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);

4
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: ^9 || ^10
core_version_requirement: ^8.9 || ^9
dependancies:
- roblib_search
- roblib_search

28
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('library');
$index = \Drupal\search_api\Entity\Index::load('default_solr_index');
$query = $index->query();
// Change the parse mode for the search.
@ -62,16 +62,10 @@ class RoblibSearchSolrsiteController extends ControllerBase {
// Restrict the search to specific languages.
//$query->setLanguages(['en']);
$query->keys($queryString);
if ($solr_type == 'BestBet') {
$query->addCondition('type', 'bestbet', '=');
$query->setFulltextFields(['title_1']);
if(str_starts_with($queryString, '"')) {
$query->keys($queryString);
} else {
$query->keys('"'.$queryString.'"');
}
$query->addCondition('type', 'bestbet');
} else {
$query->addCondition('type', 'bestbet', '<>');
}
@ -87,17 +81,13 @@ class RoblibSearchSolrsiteController extends ControllerBase {
$output['results'] = [];
foreach ($results as $result) {
$id = $result->getId();
$title = $result->getField('title');
if(empty($title)){
break;
}
$titles = $title->getValues();
$output['results'][$id]['title'] = reset($titles);
$titles = $result->getField('title')->getValues();
$output['results'][$id]['title'] = $titles[0]->getText();
$body = $result->getField('body')->getValues();
if (!empty($body)) {
$bodyOutput = strip_tags($body[0]->getText());
if (strlen($bodyOutput) > 500) {
$bodyOutput = substr($bodyOutput, 0, 499) . '...';
$bodyOutput = substr($bodyOutput, 0, 500) . '...';
}
}
$output['results'][$id]['body'] = empty($bodyOutput) ? '' : $bodyOutput;
@ -109,10 +99,6 @@ 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_site.settings');
$config = \Drupal::config('roblib_search_solr.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_site.settings');
$config = \Drupal::configFactory()->getEditable('roblib_search_solr.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();
}

18
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_site.settings')
$search_url = \Drupal::config('roblib_search_solr.settings')
->get('solr_site_url');
$settings = [
'solr_site_search_url' => $search_url,
@ -36,16 +36,8 @@ class RoblibSearchSolrSiteBestbet extends BlockBase {
],
];
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
// Reading dynamic content from external source so no caching.
if (\Drupal::currentUser()->isAnonymous()) {
// Anonymous user...
return 0;
}
}
/*public function getCacheMaxAge() {
return 1;
}*/
}

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

@ -19,13 +19,12 @@ class RoblibSearchSolrsiteGeneral extends BlockBase {
* {@inheritdoc}
*/
public function build() {
$search_url = \Drupal::config('roblib_search_solr_site.settings')
$search_url = \Drupal::config('roblib_search_solr.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,16 +37,9 @@ class RoblibSearchSolrsiteGeneral extends BlockBase {
],
];
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
// Reading dynamic content from external source so no caching.
if (\Drupal::currentUser()->isAnonymous()) {
// Anonymous user...
return 0;
}
}
/*public function getCacheMaxAge() {
return 1;
}*/
}

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

@ -1,5 +1,4 @@
<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 }}"/>
@ -7,4 +6,3 @@
<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,5 +1,4 @@
<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 }}"/>
@ -7,4 +6,3 @@
<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: ^9 || ^10
core_version_requirement: ^8.9 || ^9
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:
- drupal:views_ui
- drupal:message
- apachesolr_access
- views_ui
- message

6
roblib_search.routing.yml

@ -5,14 +5,12 @@ roblib_search.settings:
_title: 'Roblib Search Settings Form'
requirements:
_permission: 'administer site configuration'
roblib_search.landing_page:
path: '/roblib_search/{query}'
defaults:
_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'
_permission: 'access content'

14
src/Controller/RoblibSearchController.php

@ -3,9 +3,6 @@
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.
@ -19,17 +16,6 @@ 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,

6
src/Form/RoblibSearchForm.php

@ -59,7 +59,7 @@ class RoblibSearchForm extends FormBase{
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
}
/**
@ -67,14 +67,14 @@ 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());
$message->set('field_search_string', $search_string);
$message->save();
$url = Url::fromUserInput('/roblib_search/' . $search_string);
$form_state->setRedirectUrl($url);
$form_state->setRedirectUrl($url);
}
}

Loading…
Cancel
Save