diff --git a/modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsArticles.php b/modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsArticles.php index 3aa9950..7693380 100644 --- a/modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsArticles.php +++ b/modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsArticles.php @@ -30,7 +30,6 @@ class RoblibSearchEdsArticles extends BlockBase { return [ '#theme' => 'roblib_search_eds_articles', 'query' => $query, - 'spinner_path' => 'test', '#attached' => [ 'library' => [ 'roblib_search_eds/eds-article' diff --git a/modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsBooks.php b/modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsBooks.php index 250f9a7..8fd1b29 100644 --- a/modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsBooks.php +++ b/modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsBooks.php @@ -29,8 +29,7 @@ class RoblibSearchEdsBooks extends BlockBase { ]; return [ '#theme' => 'roblib_search_eds_books', - 'query' => $query, - 'spinner_path' => 'test', + //'query' => $query, '#attached' => [ 'library' => [ 'roblib_search_eds/eds-book' diff --git a/modules/solr_site/roblib_search_solr_site.info b/modules/solr_site/roblib_search_solr_site.info deleted file mode 100755 index 8e3b4b6..0000000 --- a/modules/solr_site/roblib_search_solr_site.info +++ /dev/null @@ -1,8 +0,0 @@ -name = Roblib Search Solr site -dependencies[] = roblib_search -configure = admin/roblib_search/solr_site_search -description = implements the Roblib Search local Solr site bento results -package = Roblib Search -version = 7.x-dev -core = 7.x -stylesheets[all][] = css/roblib_search_solr_site.css \ No newline at end of file diff --git a/modules/solr_site/roblib_search_solr_site.info.yml b/modules/solr_site/roblib_search_solr_site.info.yml new file mode 100644 index 0000000..c6a97e3 --- /dev/null +++ b/modules/solr_site/roblib_search_solr_site.info.yml @@ -0,0 +1,8 @@ +name: Roblib Search Solr site +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 +dependancies: + - roblib_search \ No newline at end of file diff --git a/modules/solr_site/roblib_search_solr_site.install b/modules/solr_site/roblib_search_solr_site.install deleted file mode 100755 index a4abe2d..0000000 --- a/modules/solr_site/roblib_search_solr_site.install +++ /dev/null @@ -1,2 +0,0 @@ - 'Roblib Solr Search Target configuration', - 'description' => 'Configuration for the Roblib Solr site search target', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('roblib_search_solr_site_config_form'), - 'access arguments' => array('access administration pages'), - 'type' => MENU_NORMAL_ITEM, - ); - - $items['roblib_search/solr_site/bestbet/%'] = array( - 'title' => 'BestBet', - 'page callback' => 'roblib_search_solr_site_bestbet', - 'page arguments' => array(3), - 'type' => MENU_CALLBACK, - 'access arguments' => array('search roblib solr_site'), - ); - - $items['roblib_search/solr_site/reserves/%'] = array( - 'title' => 'BestBet', - 'page callback' => 'roblib_search_solr_site_reserves', - 'page arguments' => array(3), - 'type' => MENU_CALLBACK, - 'access arguments' => array('search roblib solr_site'), - ); - $items['roblib_search/solr_site/databases/%'] = array( - 'title' => 'solr_site databases', - 'page callback' => 'roblib_search_solr_site_databases', - 'page arguments' => array(3), - 'type' => MENU_CALLBACK, - 'access arguments' => array('search roblib solr_site'), - ); - - $items['roblib_search/solr_site/guides/%'] = array( - 'title' => 'solr_site guides', - 'page callback' => 'roblib_search_solr_site_guides', - 'page arguments' => array(3), - 'type' => MENU_CALLBACK, - 'access arguments' => array('search roblib solr_site'), - ); - - $items['roblib_search/solr_site/results/%'] = array( - 'title' => 'solr_site guides', - 'page callback' => 'roblib_search_solr_site_results', - 'page arguments' => array(3), - 'type' => MENU_CALLBACK, - 'access arguments' => array('search roblib solr_site'), - ); - - - return $items; -} - -/** - * A form to manage the modules configuration. - * - * @param array $form - * A Drupal form array - * @param array $form_state - * A Drupal formstate array - * - * @return array - * A Drupal form array - */ -function roblib_search_solr_site_config_form($form, &$form_state) { - $form['roblib_search_solr_site_url'] = array( - '#type' => 'textfield', - '#title' => t('Solr url'), - '#default_value' => variable_get('roblib_search_solr_site_url', 'http://localhost:8983/solr'), - '#description' => t('The base Solr URL, for example http://localhost:8983/solr'), - '#required' => TRUE, - ); - $form['roblib_search_solr_site_num_results'] = array( - '#type' => 'textfield', - '#title' => t('Number of results to return'), - '#default_value' => variable_get('roblib_search_solr_site_num_results', '5'), - '#description' => t('The number of results to display in the Bento box'), - '#required' => TRUE, - ); - - return system_settings_form($form); -} - -/** - * Implements hook_permission(). - */ -function roblib_search_solr_site_permission() { - return array( - 'search roblib solr_site' => array( - 'title' => t('Search the solr_site target'), - 'description' => t('Search all Roblib solr_site target. This permission exposes the search blocks and allows you to see search results.'), - ), - 'administer roblib search_solr_site' => array( - 'title' => t('Administer Roblib Search Evergreen'), - 'description' => t('Administer settings for the Roblib solr_site search client.'), - ), - ); -} /** * Implements hook_theme(). */ -function roblib_search_solr_site_theme() { - // set path - $path = drupal_get_path('module', 'roblib_search_solr_site'); - $file = 'theme.inc'; - - return array( - // results page - 'roblib_search_solr_site' => array( - 'path' => $path . '/theme', - 'file' => $file, - 'template' => 'roblib-search-solr-site-results', - 'variables' => array('type' => NULL), - ), - ); +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"; + return [ + 'roblib_search_solr_site' => [ + 'variables' => ['query' => NULL, 'spinner_path' => $spinner_path], + ], + ]; } -/** - * Implements hook_block_info(). - */ -function roblib_search_solr_site_block_info() { - - $blocks['roblib_search_solr_site_bestbet'] = array( - // info: The name of the block. - 'info' => t('Roblib Solr Search Best bets'), - // Block caching options (per role, per user, etc.) - 'cache' => DRUPAL_CACHE_PER_ROLE, // default - ); - - $blocks['roblib_search_solr_site_db'] = array( - // info: The name of the block. - 'info' => t('Roblib Solr Search Databases Block'), - // Block caching options (per role, per user, etc.) - 'cache' => DRUPAL_CACHE_PER_ROLE, // default - ); - - $blocks['roblib_search_solr_site_guides'] = array( - // info: The name of the block. - 'info' => t('Roblib Solr Search Guides Block'), - // Block caching options (per role, per user, etc.) - 'cache' => DRUPAL_CACHE_PER_ROLE, // default - ); - - $blocks['roblib_search_solr_site_results'] = array( - // info: The name of the block. - 'info' => t('Roblib Solr Search Results Block'), - // Block caching options (per role, per user, etc.) - 'cache' => DRUPAL_CACHE_PER_ROLE, // default - ); - - $blocks['roblib_search_solr_site_reserves'] = array( - // info: The name of the block. - 'info' => t('Roblib Solr Search Reserves Block'), - // Block caching options (per role, per user, etc.) - 'cache' => DRUPAL_CACHE_PER_ROLE, // default - ); - - return $blocks; -} - -/** - * Add a div around our block content so we can theme our panels. - * - * By adding our divs we can theme ours without affecting other drupal panels. - * - * @param array $variables - * Drupal variables array - * @param array $hook - */ -function roblib_search_solr_site_preprocess_panels_pane(&$variables, $hook) { - switch ($variables['pane']->subtype) { - case 'roblib_search_solr_site-roblib_search_solr_site_bestbet': - $variables['title_prefix'] = '
-provides a target for the Roblib search module +provides a Solr target for the Roblib search module
' ); } diff --git a/modules/solr_site/roblib_search_solr_site.routing.yml b/modules/solr_site/roblib_search_solr_site.routing.yml new file mode 100644 index 0000000..535d4f2 --- /dev/null +++ b/modules/solr_site/roblib_search_solr_site.routing.yml @@ -0,0 +1,24 @@ +roblib_search_solr_site.settings: + path: '/admin/config/system/roblib_search_solr_site_settings' + defaults: + _form: '\Drupal\roblib_search_solr_site\Form\SolrsiteSettingsForm' + _title: 'Roblib Search Solr Site Settings Form' + requirements: + _permission: 'administer site configuration' +roblib_search_solr_site.bestbet_search: + path: '/roblib_search/solr_site/bestbet/{query}' + defaults: + _controller: '\Drupal\roblib_search_solr_site\Controller\RoblibSearchSolrsiteController::bestbetResults' + _title: 'Roblib Search Bestbet' + query: '[a-zA-Z\s]+' + requirements: + _permission: 'access content' + +roblib_search_solr_site.general_search: + path: '/roblib_search/solr_site/general/{query}' + defaults: + _controller: '\Drupal\roblib_search_solr_site\Controller\RoblibSearchSolrsiteController::generalResults' + _title: 'Roblib Search Solr Site Search' + query: '[a-zA-Z\s]+' + requirements: + _permission: 'access content' \ No newline at end of file diff --git a/modules/solr_site/src/Controller/RoblibSearchSolrsiteController.php b/modules/solr_site/src/Controller/RoblibSearchSolrsiteController.php new file mode 100644 index 0000000..374af57 --- /dev/null +++ b/modules/solr_site/src/Controller/RoblibSearchSolrsiteController.php @@ -0,0 +1,70 @@ +getResults($query, 'BestBet'); + exit(); + } + + /** + * Print JSON. + * + */ + public function generalResults($query = NULL) { + print $this->getResults($query, 'General'); + exit(); + } + + /** + * Query Solr for site results. + * @param string $query + * The search term(s) to send to Solr. + * @param string type + * The type of search, either BestBet or General. + * @return string + * A JSON string + */ + function getResults($query = NULL, $type = 'General') { + global $base_url; + $config = \Drupal::config('roblib_search_solr_site.settings'); + // Url parameters. + if (!isset($query)) { + if (isset($_GET['roblib_query'])) { + $query = $_GET['roblib_query']; + } + else { + return ''; + } + } + $query = urlencode($query); + + + /* $num_results = variable_get('roblib_search_solr_site_num_results', '5'); + $query = apachesolr_drupal_query("apachesolr"); + $encoded_query = htmlentities($query_string, ENT_QUOTES); + $query->addParam('q', $encoded_query); // keyword to be searched + $query->addParam('rows', $num_results); + $query->addParam('fq', $type); + $query->addParam('mm', '1'); + apachesolr_search_add_boost_params($query); + $response = $query->search(); + $json_results = drupal_json_encode($response); + return $json_results;*/ + + + $search_url = $base_url . '/roblib_search/solr_site/' . $type . '/' . $query; + return json_encode($query); + } +} diff --git a/modules/solr_site/src/Form/SolrsiteSettingsForm.php b/modules/solr_site/src/Form/SolrsiteSettingsForm.php new file mode 100644 index 0000000..46e3ab8 --- /dev/null +++ b/modules/solr_site/src/Form/SolrsiteSettingsForm.php @@ -0,0 +1,85 @@ + 'textfield', + '#title' => t('Solr url'), + '#default_value' => variable_get('roblib_search_solr_site_url', 'http://localhost:8983/solr'), + '#description' => t('The base Solr URL, for example http://localhost:8983/solr'), + '#required' => TRUE, + ); + $form['roblib_search_solr_site_num_results'] = array( + '#type' => 'textfield', + '#title' => t('Number of results to return'), + '#default_value' => variable_get('roblib_search_solr_site_num_results', '5'), + '#description' => t('The number of results to display in the Bento box'), + '#required' => TRUE, + ); + + return system_settings_form($form); + */ + $form['solr_site_url'] = array( + '#type' => 'textfield', + '#title' => t('Solr URL'), + '#default_value' => $config->get('solr_site_url'), + '#description' => t('The base Solr URL, for example http://localhost:8983/solr'), + '#required' => TRUE, + ); + + $form['solr_site_num_results'] = array( + '#type' => 'textfield', + '#title' => 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'), + '#required' => TRUE, + ); + $form['actions']['submit'] = [ + '#type' => 'submit', + '#value' => t('Save'), + '#button_type' => 'primary', + ]; + return $form; + } + + /** + * {@inheritdoc} + */ + public function validateForm(array &$form, FormStateInterface $form_state) { + + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $config = \Drupal::configFactory()->getEditable('roblib_search_eds.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(); + } + +} diff --git a/modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteBestbet.php b/modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteBestbet.php new file mode 100644 index 0000000..030932a --- /dev/null +++ b/modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteBestbet.php @@ -0,0 +1,39 @@ +getSchemeAndHttpHost(); + $search_url = \Drupal::config('roblib_search_solr_site.settings') + ->get('solr_site_url'); + $settings = [ + 'solr_site_search_url' => $search_url, + ]; + return [ + '#theme' => 'roblib_search_solr_site', + 'query' => $query, + '#attached' => [ + 'library' => [ + 'roblib_search_solr_site/solr_site' + ], + 'drupalSettings' => $settings, + ], + ]; + } +} diff --git a/modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteGeneral.php b/modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteGeneral.php new file mode 100644 index 0000000..79e1f01 --- /dev/null +++ b/modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteGeneral.php @@ -0,0 +1,40 @@ +getSchemeAndHttpHost(); + $search_url = \Drupal::config('roblib_search_solr_site.settings') + ->get('solr_site_url'); + $settings = [ + 'solr_site_search_url' => $search_url, + ]; + return [ + '#theme' => 'roblib_search_solr_site', + 'query' => $query, + '#attached' => [ + 'library' => [ + 'roblib_search_solr_site/solr_site' + ], + 'drupalSettings' => $settings, + ], + ]; + } + +} diff --git a/modules/solr_site/theme/roblib-search-solr-site-results.tpl.php b/modules/solr_site/templates/roblib-search-solr-site-results.html.twig similarity index 100% rename from modules/solr_site/theme/roblib-search-solr-site-results.tpl.php rename to modules/solr_site/templates/roblib-search-solr-site-results.html.twig diff --git a/modules/solr_site/theme/theme.inc b/modules/solr_site/templates/theme.inc similarity index 100% rename from modules/solr_site/theme/theme.inc rename to modules/solr_site/templates/theme.inc diff --git a/roblib_search.module b/roblib_search.module index 80e5794..90ac1cc 100644 --- a/roblib_search.module +++ b/roblib_search.module @@ -13,6 +13,9 @@ function roblib_search_theme($existing, $type, $theme, $path) { 'roblib_search_results' => [ 'variables' => ['query' => NULL], ], + 'roblib_search_other_sources' => [ + 'variables' => ['query' => NULL], + ], ]; } diff --git a/src/Plugin/Block/RoblibSearchOtherSourcesBlock.php b/src/Plugin/Block/RoblibSearchOtherSourcesBlock.php new file mode 100644 index 0000000..3b662e3 --- /dev/null +++ b/src/Plugin/Block/RoblibSearchOtherSourcesBlock.php @@ -0,0 +1,34 @@ + 'roblib_search_other_sources', + '#query' => $query, + ]; + } + +} diff --git a/theme/roblib-search-other-sources.tpl.php b/templates/roblib-search-other-sources.html.twig similarity index 52% rename from theme/roblib-search-other-sources.tpl.php rename to templates/roblib-search-other-sources.html.twig index 41edc07..14a683d 100644 --- a/theme/roblib-search-other-sources.tpl.php +++ b/templates/roblib-search-other-sources.html.twig @@ -1,21 +1,11 @@ - - \ No newline at end of file diff --git a/theme/theme.inc b/theme/theme.inc index c6f45aa..a8fbb82 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -5,7 +5,7 @@ * and open the template in the editor. */ -function roblib_search_preprocess_roblib_search_other_sources(&$variables) { +/*function roblib_search_preprocess_roblib_search_other_sources(&$variables) { global $base_url; if (!isset($query)) { if (isset($_GET['roblib_query'])) { @@ -16,5 +16,5 @@ function roblib_search_preprocess_roblib_search_other_sources(&$variables) { } } $variables['query'] = urlencode($query); -} +}*/ ?>