Browse Source

initial Drupal 11 updates

2.x
Paul Pound 2 weeks ago
parent
commit
899caea20a
  1. 6
      modules/roblib_search_eds/roblib_search_eds.info.yml
  2. 4
      modules/roblib_search_eds/roblib_search_eds.libraries.yml
  3. 17
      modules/roblib_search_eds/roblib_search_eds.module
  4. 44
      modules/roblib_search_eds/src/Controller/RoblibSearchEdsController.php
  5. 50
      modules/roblib_search_eds/src/Form/EdsSettingsForm.php
  6. 1
      modules/roblib_search_eds/src/Lib/EBSCOAPI.php
  7. 7
      modules/roblib_search_eds/src/Lib/EBSCODocument.php
  8. 3
      modules/roblib_search_eds/src/Lib/EBSCOResponse.php
  9. 1
      modules/roblib_search_eds/src/Lib/sanitizer.class.php
  10. 6
      modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsArticles.php
  11. 6
      modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsBooks.php
  12. 7
      modules/solr_site/roblib_search_solr_site.info.yml
  13. 4
      modules/solr_site/roblib_search_solr_site.libraries.yml
  14. 82
      modules/solr_site/roblib_search_solr_site.module
  15. 37
      modules/solr_site/src/Controller/RoblibSearchSolrsiteController.php
  16. 14
      modules/solr_site/src/Form/SolrsiteSettingsForm.php
  17. 5
      modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteBestbet.php
  18. 5
      modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteGeneral.php
  19. 8
      roblib_search.info.yml
  20. 19
      roblib_search.module
  21. 36
      src/Controller/RoblibSearchController.php
  22. 10
      src/Form/RoblibSearchForm.php
  23. 10
      src/Form/RoblibSearchSettingsForm.php
  24. 5
      src/Plugin/Block/RoblibSearchBoxBlock.php
  25. 10
      src/Plugin/Block/RoblibSearchOtherSourcesBlock.php
  26. 20
      theme/theme.inc

6
modules/roblib_search_eds/roblib_search_eds.info.yml

@ -3,6 +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: ^9 || ^10
dependancies:
- roblib_search
core_version_requirement: ^10 || ^11
dependencies:
- roblib_search:roblib_search

4
modules/roblib_search_eds/roblib_search_eds.libraries.yml

@ -6,7 +6,9 @@ eds-book:
js:
js/eds_results_book.js: {}
dependencies:
- core/jquery
- core/drupal
- core/drupalSettings
eds-article:
version: 1.x
css:
@ -15,5 +17,7 @@ eds-article:
js:
js/eds_results_article.js: {}
dependencies:
- core/jquery
- core/drupal
- core/drupalSettings

17
modules/roblib_search_eds/roblib_search_eds.module

@ -5,13 +5,14 @@
* Implementation of Roblib search for searching EDSAPI (EBSCO) targets.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_theme().
*/
function roblib_search_eds_theme($existing, $type, $theme, $path) {
$modulePath = \Drupal::service('module_handler')->getModule('roblib_search')
->getPath();
$spinner_path = '/' . $modulePath . "/img/spinner.gif";
$modulePath = \Drupal::service('extension.list.module')->getPath('roblib_search');
$spinner_path = '/' . $modulePath . '/img/spinner.gif';
return [
'roblib_search_eds_books' => [
'variables' => ['query' => NULL, 'spinner_path' => $spinner_path],
@ -24,14 +25,10 @@ function roblib_search_eds_theme($existing, $type, $theme, $path) {
/**
* Implements hook_help().
*
* @param type $path
* @param type $arg
* @return type
*/
function roblib_search_eds_help($path, $arg) {
switch ($path) {
case 'admin/help#roblib_search_eds':
function roblib_search_eds_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.roblib_search_eds':
return t(
'<p>
provides a EDSAPI target for the Roblib search module. This target uses javascript

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

@ -4,28 +4,25 @@ namespace Drupal\roblib_search_eds\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\roblib_search_eds\Lib\EBSCOAPI;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* Controller for d3 graphs.
* Controller returning EDS search results as JSON.
*/
class RoblibSearchEdsController extends ControllerBase {
/**
* Print JSON.
*
* Returns EDS article results as JSON.
*/
public function articleResults($query = NULL) {
print $this->eds_get_results($query, 'Articles');
exit();
return JsonResponse::fromJsonString($this->eds_get_results($query, 'Articles'));
}
/**
* Print JSON.
*
* Returns EDS book results as JSON.
*/
public function bookResults($query = NULL) {
print $this->eds_get_results($query, 'Books');
exit();
return JsonResponse::fromJsonString($this->eds_get_results($query, 'Books'));
}
/**
@ -37,16 +34,14 @@ class RoblibSearchEdsController extends ControllerBase {
* @return string
* A JSON string
*/
function eds_get_results($query = NULL, $type = 'Articles') {
//drupal_add_css(drupal_get_path('module', 'roblib_search_eds') . '/css/roblib_search_eds.theme.css');
$config = \Drupal::config('roblib_search_eds.settings');
public function eds_get_results($query = NULL, $type = 'Articles') {
$config = $this->config('roblib_search_eds.settings');
$request = \Drupal::request();
// Url parameters.
if (!isset($query)) {
if (isset($_GET['roblib_query'])) {
$query = $_GET['roblib_query'];
}
else {
return '';
$query = $request->query->get('roblib_query');
if (!isset($query)) {
return '{}';
}
}
$limiters = '';
@ -62,7 +57,7 @@ class RoblibSearchEdsController extends ControllerBase {
$query = '(' . $query . ') ' . $limiters;
$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"]);
$is_local_ip = $eds_api->connector()->isGuestIPAddress($request->getClientIp());
$eds_api->isGuest(FALSE);
$output = $eds_api->apiSearch($search, $filters, 1, $number_per_page);
@ -79,8 +74,8 @@ class RoblibSearchEdsController extends ControllerBase {
* @return string
* The limiters to append to the query.
*/
function get_eds_query_limiters($type) {
$config = \Drupal::config('roblib_search_eds.settings');
public function get_eds_query_limiters($type) {
$config = $this->config('roblib_search_eds.settings');
$limiters = 'n';
switch ($type) {
case 'Articles':
@ -97,9 +92,9 @@ class RoblibSearchEdsController extends ControllerBase {
return $limiters;
}
function build_eds_config_arr($type) {
$ebsco_config = array();
$roblib_search_config = \Drupal::config('roblib_search_eds.settings');
public function build_eds_config_arr($type) {
$ebsco_config = [];
$roblib_search_config = $this->config('roblib_search_eds.settings');
$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
@ -111,6 +106,9 @@ class RoblibSearchEdsController extends ControllerBase {
$ebsco_config['rest_url'] = $roblib_search_config->get('eds_rest_url');
$ebsco_config['guest'] = $roblib_search_config->get('eds_guest');
$ebsco_config['autocomplete'] = '';
$ebsco_config['interface'] = '';
$ebsco_config['organization'] = '';
$ebsco_config['log'] = 0;
return $ebsco_config;
}

50
modules/roblib_search_eds/src/Form/EdsSettingsForm.php

@ -23,96 +23,96 @@ class EdsSettingsForm extends FormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = \Drupal::config('roblib_search_eds.settings');
$config = $this->config('roblib_search_eds.settings');
/* $form['eds_rest_url'] = array(
'#type' => 'textfield',
'#title' => t('EDS Rest endpoint'),
'#title' => $this->t('EDS Rest endpoint'),
'#default_value' => $config->get('eds_rest_url'),
'#description' => t('The base EDS URL, for example https://eds-api.ebscohost.com/edsapi/rest'),
'#description' => $this->t('The base EDS URL, for example https://eds-api.ebscohost.com/edsapi/rest'),
'#required' => TRUE,
);
$form['eds_auth_url'] = array(
'#type' => 'textfield',
'#title' => t('EDS Auth endpoint'),
'#title' => $this->t('EDS Auth endpoint'),
'#default_value' => $config->get('eds_auth_url'),
'#description' => t('The EDS Auth endpoint, for example https://eds-api.ebscohost.com/Authservice/rest'),
'#description' => $this->t('The EDS Auth endpoint, for example https://eds-api.ebscohost.com/Authservice/rest'),
'#required' => TRUE,
);
$form['eds_user'] = array(
'#type' => 'textfield',
'#title' => t('EDS user'),
'#title' => $this->t('EDS user'),
'#default_value' => $config->get('eds_user'),
'#description' => t('EDS user, for example username'),
'#description' => $this->t('EDS user, for example username'),
'#required' => TRUE,
);
$form['eds_pass'] = array(
'#type' => 'textfield',
'#title' => t('EDS password'),
'#title' => $this->t('EDS password'),
'#default_value' => $config->get('eds_pass'),
'#description' => t('EDS password, for example password'),
'#description' => $this->t('EDS password, for example password'),
'#required' => TRUE,
);
$form['eds_guest'] = array(
'#type' => 'textfield',
'#title' => t('EDS Guest access'),
'#title' => $this->t('EDS Guest access'),
'#default_value' => $config->get('eds_guest'),
'#description' => t('EDS Guest access, y = guest access, n = not a guest'),
'#description' => $this->t('EDS Guest access, y = guest access, n = not a guest'),
'#required' => TRUE,
);*/
$form['eds_local_ip'] = array(
'#type' => 'textfield',
'#title' => t('EDS Local IP'),
'#title' => $this->t('EDS Local IP'),
'#default_value' => $config->get('eds_local_ip'),
'#description' => t('Local IP address prefix, i. 137.149.'),
'#description' => $this->t('Local IP address prefix, i. 137.149.'),
'#required' => TRUE,
);
$form['eds_article_profile'] = array(
'#type' => 'textfield',
'#title' => t('EDS Article profile'),
'#title' => $this->t('EDS Article profile'),
'#default_value' => $config->get('eds_article_profile'),
'#description' => t('EDS profile, for example edsapi'),
'#description' => $this->t('EDS profile, for example edsapi'),
'#required' => TRUE,
);
$form['eds_book_profile'] = array(
'#type' => 'textfield',
'#title' => t('EDS Book profile'),
'#title' => $this->t('EDS Book profile'),
'#default_value' => $config->get('eds_book_profile'),
'#description' => t('EDS Book profile, for example apilite'),
'#description' => $this->t('EDS Book profile, for example apilite'),
'#required' => TRUE,
);
$form['eds_num_results'] = array(
'#type' => 'textfield',
'#title' => t('Number of results to return'),
'#title' => $this->t('Number of results to return'),
'#default_value' => $config->get('eds_num_results'),
'#description' => t('The number of results to display in the Bento box, usurally 5'),
'#description' => $this->t('The number of results to display in the Bento box, usurally 5'),
'#required' => TRUE,
);
$form['eds_article_limiters'] = array(
'#type' => 'textarea',
'#title' => t('The limiters for Article searches'),
'#title' => $this->t('The limiters for Article searches'),
'#default_value' => $config->get('eds_article_limiters'),
'#description' => t('Specify the Publication Types to use as limiters for Article searches. Formatted similar to
'#description' => $this->t('Specify the Publication Types to use as limiters for Article searches. Formatted similar to
AND (PT Article OR PT Magazines OR PT News OR PT Academic Journals OR PT Conference Materials)'),
'#required' => TRUE,
);
$form['eds_book_limiters'] = array(
'#type' => 'textarea',
'#title' => t('The limiters for Books and Media searches'),
'#title' => $this->t('The limiters for Books and Media searches'),
'#default_value' => $config->get('eds_book_limiters'),
'#description' => t('Specify the Publication Types to use as limiters for Article searches. Formatted similar to
'#description' => $this->t('Specify the Publication Types to use as limiters for Article searches. Formatted similar to
AND (PT Book OR PT Video OR PT Audio'),
'#required' => TRUE,
);
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => t('Save'),
'#value' => $this->t('Save'),
'#button_type' => 'primary',
];
return $form;
@ -129,7 +129,7 @@ class EdsSettingsForm extends FormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = \Drupal::configFactory()->getEditable('roblib_search_eds.settings');
$config = $this->configFactory()->getEditable('roblib_search_eds.settings');
//$config->set('eds_rest_url', $form_state->getValue('eds_rest_url'))->save();
//$config->set('eds_auth_url', $form_state->getValue('eds_auth_url'))->save();
//$config->set('eds_user', $form_state->getValue('eds_user'))->save();

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

@ -370,6 +370,7 @@ class EBSCOAPI {
//$headers = array(
// 'x-authenticationToken: '.$this->authenticationToken(),
//);
$headers = [];
$response = $this->connector()->requestSessionToken($headers);
// Raise the exception so that any code running this method should exit immediately.

7
modules/roblib_search_eds/src/Lib/EBSCODocument.php

@ -54,6 +54,13 @@ class EBSCODocument {
*/
private $params = array();
/**
* The citation style terms (declared to avoid PHP 8.2+ dynamic properties).
*
* @var array|null
*/
private $citationStylesTerms = NULL;
/**
* The associative array of EBSCO results returned by a Search API call
* #global array.

3
modules/roblib_search_eds/src/Lib/EBSCOResponse.php

@ -358,8 +358,7 @@ class EBSCOResponse
if (isset($record->RecordInfo->BibRecord->BibRelationships->HasContributorRelationships)) {
foreach ($record->RecordInfo->BibRecord->BibRelationships->HasContributorRelationships->HasContributor as $contributor) {
$nameFull = $contributor->PersonEntity->Name->NameFull ?
(string) $contributor->PersonEntity->Name->NameFull : '';
$nameFull = (string) ($contributor->PersonEntity?->Name?->NameFull ?? '');
$result['RecordInfo']['BibRelationships']['HasContributorRelationships'][] = array(
'NameFull' => $nameFull,

1
modules/roblib_search_eds/src/Lib/sanitizer.class.php

@ -43,6 +43,7 @@ class HTML_Sanitizer {
*/
private $_allowedTags;
private $_allowJavascriptEvents;
private $_allowDOMEvents;
private $_allowJavascriptInUrls;
private $_allowObjects;
private $_allowScript;

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

@ -29,7 +29,6 @@ class RoblibSearchEdsArticles extends BlockBase {
];
return [
'#theme' => 'roblib_search_eds_articles',
'query' => $query,
'#attached' => [
'library' => [
'roblib_search_eds/eds-article'
@ -44,10 +43,7 @@ class RoblibSearchEdsArticles extends BlockBase {
*/
public function getCacheMaxAge() {
// Reading dynamic content from external source so no caching.
if (\Drupal::currentUser()->isAnonymous()) {
// Anonymous user...
return 0;
}
return 0;
}
}

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

@ -29,7 +29,6 @@ class RoblibSearchEdsBooks extends BlockBase {
];
return [
'#theme' => 'roblib_search_eds_books',
//'query' => $query,
'#attached' => [
'library' => [
'roblib_search_eds/eds-book'
@ -44,10 +43,7 @@ class RoblibSearchEdsBooks extends BlockBase {
*/
public function getCacheMaxAge() {
// Reading dynamic content from external source so no caching.
if (\Drupal::currentUser()->isAnonymous()) {
// Anonymous user...
return 0;
}
return 0;
}

7
modules/solr_site/roblib_search_solr_site.info.yml

@ -3,6 +3,7 @@ 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
dependancies:
- roblib_search
core_version_requirement: ^10 || ^11
dependencies:
- roblib_search:roblib_search
- search_api:search_api

4
modules/solr_site/roblib_search_solr_site.libraries.yml

@ -6,10 +6,14 @@ solr-site:
js:
js/solr_site_results.js: {}
dependencies:
- core/jquery
- core/drupal
- core/drupalSettings
solr-bestbet:
version: 1.x
js:
js/solr_site_bestbet.js: {}
dependencies:
- core/jquery
- core/drupal
- core/drupalSettings

82
modules/solr_site/roblib_search_solr_site.module

@ -2,18 +2,17 @@
/**
* @file
* Implementation of Roblib search for searching several targets.
* Implementation of Roblib search for the local Solr (Search API) site index.
*/
/**
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_theme().
*/
function roblib_search_solr_site_theme($existing, $type, $theme, $path) {
$modulePath = \Drupal::service('module_handler')->getModule('roblib_search')
->getPath();
$spinner_path = '/' . $modulePath . "/img/spinner.gif";
$modulePath = \Drupal::service('extension.list.module')->getPath('roblib_search');
$spinner_path = '/' . $modulePath . '/img/spinner.gif';
return [
'roblib_search_solr_site_results' => [
'variables' => ['solr_type' => 'results', 'spinner_path' => $spinner_path],
@ -24,77 +23,12 @@ function roblib_search_solr_site_theme($existing, $type, $theme, $path) {
];
}
/**
* Send the query to solr but limit the results so it doesn't include certain content.
*
* Print json and exit so the javascript can consume the json.
*
* @param string $query
* The solr search string.
*/
/*function roblib_search_solr_site_results($query) {
print roblib_search_solr_site_get_results($query, '-bundle:bestbet');
exit();
}*/
/**
* Send the query to solr but limit the results so it only includes content of type bestbet.
*
* Print json and exit so the javascript can consume the json.
*
* @param string $query
* The solr search string.
*/
/*function roblib_search_solr_site_bestbet($query) {
$query = str_replace('"', '', $query);
$json = roblib_search_solr_site_get_results("sort_label:$query", 'bundle:bestbet');
$json = roblib_search_solr_site_add_url($json);
print $json;
exit();
}*/
/**
*
* Updates the json passed in with a url directly to the target of the link field.
* This information is not in solr as it comes from a custom field.
*
*
* @param string $json
* The json string returned from the solr query.
*
* @return string
* json we got from solr with an updated url directly to the target of the link field
*/
/*function roblib_search_solr_site_add_url($json) {
$responses = json_decode($json);
foreach ($responses->response->docs as &$doc) {
$nid = $doc->entity_id;
// The link field is a complex field and we get the text in solr but not the actual url.
// Since best best will only every return one result it's not much overhead to load the node
// and get the value of the link field. probably less overhead then installing additional
// modules to get the url in solr.
$node = node_load($nid);
$url = $node->field_link['und'][0]['url'];
$doc->url = $url;
}
return json_encode($responses);
}
*/
/**
* Implements hook_help().
*/
function roblib_search_solr_site_help($path, $arg) {
switch ($path) {
case 'admin/help#roblib_search_solr_site':
return t(
'<p>
provides a Solr target for the Roblib search module
</p>'
);
function roblib_search_solr_site_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.roblib_search_solr_site':
return t('<p>Provides a Solr target for the Roblib search module.</p>');
}
}

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

@ -3,28 +3,26 @@
namespace Drupal\roblib_search_solr_site\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\search_api\Entity\Index;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* Controller for d3 graphs.
* Controller returning Search API (Solr) site results as JSON.
*/
class RoblibSearchSolrsiteController extends ControllerBase {
/**
* Print JSON.
*
* Returns best bet results as JSON.
*/
public function bestbetResults($query = NULL) {
print $this->getResults($query, 'BestBet');
exit();
return new JsonResponse($this->getResults($query, 'BestBet'));
}
/**
* Print JSON.
*
* Returns general site results as JSON.
*/
public function generalResults($query = NULL) {
print $this->getResults($query, 'General');
exit();
return new JsonResponse($this->getResults($query, 'General'));
}
/**
@ -33,24 +31,20 @@ class RoblibSearchSolrsiteController extends ControllerBase {
* The search term(s) to send to Solr.
* @param string type
* The type of search, either BestBet or General.
* @return string
* A JSON string
* @return array
* The results, ready to be JSON encoded.
*/
function getResults($queryString = NULL, $solr_type = 'General') {
global $base_url;
$config = \Drupal::config('roblib_search_solr_site.settings');
public function getResults($queryString = NULL, $solr_type = 'General') {
// Url parameters.
if (!isset($queryString)) {
if (isset($_GET['roblib_query'])) {
$queryString = $_GET['roblib_query'];
}
else {
return '';
$queryString = \Drupal::request()->query->get('roblib_query');
if (!isset($queryString)) {
return [];
}
}
//$queryString = urlencode($queryString);
// TODO make the index configurable.
$index = \Drupal\search_api\Entity\Index::load('library');
$index = Index::load('library');
$query = $index->query();
// Change the parse mode for the search.
@ -117,8 +111,7 @@ class RoblibSearchSolrsiteController extends ControllerBase {
$output['results'][$id]['field_link'] = empty($links) ? '' : $links;
}
echo json_encode($output);
exit();
return $output;
}
}

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

@ -23,26 +23,26 @@ class SolrsiteSettingsForm extends FormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = \Drupal::config('roblib_search_solr_site.settings');
$config = $this->config('roblib_search_solr_site.settings');
$form['solr_site_url'] = array(
'#type' => 'textfield',
'#title' => t('Solr URL'),
'#title' => $this->t('Solr URL'),
'#default_value' => $config->get('solr_site_url'),
'#description' => t('The base Solr URL, for example /search/node?keys='),
'#description' => $this->t('The base Solr URL, for example /search/node?keys='),
'#required' => TRUE,
);
$form['solr_site_num_results'] = array(
'#type' => 'textfield',
'#title' => t('Number of results to return'),
'#title' => $this->t('Number of results to return'),
'#default_value' => $config->get('solr_site_num_results'),
'#description' => t('The number of results to display in the Bento box'),
'#description' => $this->t('The number of results to display in the Bento box'),
'#required' => TRUE,
);
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => t('Save'),
'#value' => $this->t('Save'),
'#button_type' => 'primary',
];
return $form;
@ -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 = $this->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();
}

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

@ -42,10 +42,7 @@ class RoblibSearchSolrSiteBestbet extends BlockBase {
*/
public function getCacheMaxAge() {
// Reading dynamic content from external source so no caching.
if (\Drupal::currentUser()->isAnonymous()) {
// Anonymous user...
return 0;
}
return 0;
}
}

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

@ -44,10 +44,7 @@ class RoblibSearchSolrsiteGeneral extends BlockBase {
*/
public function getCacheMaxAge() {
// Reading dynamic content from external source so no caching.
if (\Drupal::currentUser()->isAnonymous()) {
// Anonymous user...
return 0;
}
return 0;
}
}

8
roblib_search.info.yml

@ -1,10 +1,8 @@
name: Roblib Search
type: module
core_version_requirement: ^9 || ^10
core_version_requirement: ^10 || ^11
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
dependencies:
- message:message

19
roblib_search.module

@ -5,6 +5,8 @@
* Implementation of Roblib search for searching several targets.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_theme().
*/
@ -20,23 +22,12 @@ function roblib_search_theme($existing, $type, $theme, $path) {
}
/**
* Implements hook_init().
*/
/*function roblib_search_init() {
drupal_add_js(drupal_get_path('module', 'roblib_search') . '/js/imagesloaded.pkg.min.js');
drupal_add_js(drupal_get_path('module', 'roblib_search') . '/js/roblib_search.js');
drupal_add_css(drupal_get_path('module', 'roblib_search') . '/css/jquery.qtip.min.css');
}*/
/**
* Implements hook_help().
*/
function roblib_search_help($path, $arg) {
switch ($path) {
case 'admin/help#roblib_search':
function roblib_search_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.roblib_search':
return t(
'<p>
The Roblib Search is a module to allow searching across multiple targets.

36
src/Controller/RoblibSearchController.php

@ -2,35 +2,43 @@
namespace Drupal\roblib_search\Controller;
use Drupal\Component\Utility\Html;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Component\Utility\Html;
use Symfony\Component\HttpFoundation\Request;
/**
* Controller for d3 graphs.
* Controller for the Roblib Search landing page.
*/
class RoblibSearchController extends ControllerBase {
/**
* Display the markup.
* Display the search results landing page.
*
* @return array
* A renderable array.
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request.
* @param string|null $query
* The search query from the path.
*
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse
* A renderable array, or a redirect when a roblib_query parameter is used.
*/
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.'));
public function searchResults(Request $request, $query = NULL) {
$roblib_query = $request->query->get('roblib_query');
if (!empty($roblib_query)) {
$roblib_query = str_replace('/', ' ', $roblib_query);
$roblib_query = trim(Html::decodeEntities($roblib_query));
if (empty($roblib_query)) {
$this->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]);
}
else {
$url = Url::fromRoute('roblib_search.landing_page', ['query' => $roblib_query]);
}
return new RedirectResponse($url->toString());
}
return [
return [
'#theme' => 'roblib_search_results',
'#query' => $query,
];

10
src/Form/RoblibSearchForm.php

@ -4,7 +4,6 @@ namespace Drupal\roblib_search\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\Html;
use Drupal\Core\Url;
use Drupal\message\Entity\Message;
@ -27,12 +26,7 @@ class RoblibSearchForm extends FormBase{
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
if (isset($_GET['roblib_query'])) {
$query = $_GET['roblib_query'];
}
else {
$query = '';
}
$query = $this->getRequest()->query->get('roblib_query', '');
$form['simple'] = array(
'#type' => 'container',
'#attributes' => array(
@ -50,7 +44,7 @@ class RoblibSearchForm extends FormBase{
);
$form['simple']['submit'] = array(
'#type' => 'submit',
'#value' => t('search')
'#value' => $this->t('search')
);
return $form;
}

10
src/Form/RoblibSearchSettingsForm.php

@ -23,17 +23,17 @@ class RoblibSearchSettingsForm extends FormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = \Drupal::config('roblib_search.settings');
$config = $this->config('roblib_search.settings');
$form['search_panel_page'] = array(
'#type' => 'textfield',
'#title' => t('Path to the roblib search panel page'),
'#title' => $this->t('Path to the roblib search panel page'),
'#default_value' => $config->get('search_panel_page'),
'#description' => t('The Path to the Roblib Search Panel, for example /roblib/panel'),
'#description' => $this->t('The Path to the Roblib Search Panel, for example /roblib/panel'),
'#required' => TRUE,
);
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => t('Save'),
'#value' => $this->t('Save'),
'#button_type' => 'primary',
];
return $form;
@ -50,7 +50,7 @@ class RoblibSearchSettingsForm extends FormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = \Drupal::configFactory()->getEditable('roblib_search.settings');
$config = $this->configFactory()->getEditable('roblib_search.settings');
$config->set('search_panel_page', $form_state->getValue('search_panel_page'))->save();
}

5
src/Plugin/Block/RoblibSearchBoxBlock.php

@ -3,6 +3,7 @@
namespace Drupal\roblib_search\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\roblib_search\Form\RoblibSearchForm;
/**
* Provides a search form.
@ -19,8 +20,6 @@ class RoblibSearchBoxBlock extends BlockBase {
* {@inheritdoc}
*/
public function build() {
$form = \Drupal::formBuilder()->getForm('\Drupal\roblib_search\Form\RoblibSearchForm');
return $form;
return \Drupal::formBuilder()->getForm(RoblibSearchForm::class);
}
}

10
src/Plugin/Block/RoblibSearchOtherSourcesBlock.php

@ -18,11 +18,10 @@ class RoblibSearchOtherSourcesBlock extends BlockBase {
/**
* {@inheritdoc}
*/
///roblib_search/
public function build() {
$prefix = '/roblib_search/';
$query = $_SERVER['REQUEST_URI'];
if (substr($query, 0, strlen($prefix)) == $prefix) {
$query = \Drupal::request()->getRequestUri();
if (str_starts_with($query, $prefix)) {
$query = substr($query, strlen($prefix));
}
return [
@ -31,8 +30,11 @@ class RoblibSearchOtherSourcesBlock extends BlockBase {
];
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
// don't cache this block
// Don't cache this block.
return 0;
}

20
theme/theme.inc

@ -1,20 +0,0 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*function roblib_search_preprocess_roblib_search_other_sources(&$variables) {
global $base_url;
if (!isset($query)) {
if (isset($_GET['roblib_query'])) {
$query = $_GET['roblib_query'];
}
else {
$query = '';
}
}
$variables['query'] = urlencode($query);
}*/
?>
Loading…
Cancel
Save