Bento box search with multiple targets
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

47 lines
1.4 KiB

<?php
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 Symfony\Component\HttpFoundation\Request;
/**
* Controller for the Roblib Search landing page.
*/
class RoblibSearchController extends ControllerBase {
/**
* Display the search results landing page.
*
* @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(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' => $roblib_query]);
}
return new RedirectResponse($url->toString());
}
return [
'#theme' => 'roblib_search_results',
'#query' => $query,
];
}
}