Browse Source

added themeing so search form can pass query to landing page of main module

d9
ppound 3 years ago
parent
commit
7ab0c77868
  1. 11
      roblib_search.module
  2. 11
      roblib_search.routing.yml
  3. 25
      src/Controller/RoblibSearchController.php
  4. 11
      src/Form/RoblibSearchForm.php
  5. 3
      templates/roblib-search-results.html.twig

11
roblib_search.module

@ -62,6 +62,17 @@ function roblib_search_block_info() {
);
}*/
/**
* Implements hook_theme().
*/
function roblib_search_theme($existing, $type, $theme, $path) {
return [
'roblib_search_results' => [
'variables' => ['query' => NULL],
],
];
}
/**

11
roblib_search.routing.yml

@ -4,4 +4,13 @@ roblib_search.settings:
_form: '\Drupal\roblib_search\Form\RoblibSearchSettingsForm'
_title: 'Roblib Search Settings Form'
requirements:
_permission: 'administer site configuration'
_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]+'
requirements:
_permission: 'access content'

25
src/Controller/RoblibSearchController.php

@ -0,0 +1,25 @@
<?php
namespace Drupal\roblib_search\Controller;
use Drupal\Core\Controller\ControllerBase;
/**
* Controller for d3 graphs.
*/
class RoblibSearchController extends ControllerBase {
/**
* Display the markup.
*
* @return array
* A renderable array.
*/
public function searchResults($query = NULL) {
return [
'#theme' => 'roblib_search_results',
'#query' => $query,
];
}
}

11
src/Form/RoblibSearchForm.php

@ -5,6 +5,7 @@ namespace Drupal\roblib_search\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\Html;
use Drupal\Core\Url;
/**
* Config form for module
@ -63,17 +64,11 @@ class RoblibSearchForm extends FormBase{
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
global $base_url;
//$form_state->rebuild(TRUE);
$search_string = $form_state->getValue('roblib_search_simple_search_query');
$search_string = Html::escape($search_string);
//roblib_search_log_query($search_string);
$config = \Drupal::config('roblib_search.settings');
$redirect_url = $config->get('search_panel_page');
$redirect_url = $base_url . '/' . $redirect_url;
//TODO redirect to the search page
$form_state->setRedirect('<front>');
$url = Url::fromUserInput('/roblib_search/' . $search_string);
$form_state->setRedirectUrl($url);
}
}

3
templates/roblib-search-results.html.twig

@ -0,0 +1,3 @@
<div id="roblib-search-results">
{{ query }}
</div>
Loading…
Cancel
Save