From ae2f7960ac064ccc7251f0131ddbba6396f9fae1 Mon Sep 17 00:00:00 2001 From: ppound Date: Fri, 1 Oct 2021 14:00:28 -0300 Subject: [PATCH] added dependancy on the message module so we can log search requests --- roblib_search.info.yml | 3 ++- roblib_search.module | 17 ----------------- src/Form/RoblibSearchForm.php | 8 +++++++- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/roblib_search.info.yml b/roblib_search.info.yml index e086b08..87555c1 100644 --- a/roblib_search.info.yml +++ b/roblib_search.info.yml @@ -6,4 +6,5 @@ description: Provides a search form and fires a hook when the search is submitte package: Roblib Search dependancies: - apachesolr_access - - views_ui \ No newline at end of file + - views_ui + - message \ No newline at end of file diff --git a/roblib_search.module b/roblib_search.module index f058dfc..0da927b 100644 --- a/roblib_search.module +++ b/roblib_search.module @@ -45,23 +45,6 @@ function roblib_search_block_info() { return $blocks; } -/** - * Implements hook_theme(). - */ -/*function roblib_search_theme() { - $path = drupal_get_path('module', 'roblib_search'); - $file = 'theme.inc'; - - return array( - 'roblib_search_other_sources' => array( - 'path' => $path . '/theme', - 'file' => $file, - 'template' => 'roblib-search-other-sources', - 'variables' => array('results' => NULL), - ) - ); -}*/ - /** * Implements hook_theme(). */ diff --git a/src/Form/RoblibSearchForm.php b/src/Form/RoblibSearchForm.php index 09a3cf1..143505d 100644 --- a/src/Form/RoblibSearchForm.php +++ b/src/Form/RoblibSearchForm.php @@ -6,6 +6,8 @@ use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Component\Utility\Html; use Drupal\Core\Url; +use Drupal\message\Entity\Message; + /** * Config form for module @@ -66,7 +68,11 @@ 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); - //roblib_search_log_query($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); }