Skip to content

Commit

Permalink
feat(routes): use named routes in search
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Jan 18, 2018
1 parent 8edbceb commit 6f085cd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
10 changes: 10 additions & 0 deletions mod/search/elgg-plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'routes' => [
'default:search' => [
'path' => '/search/{route_query?}',
'resource' => 'search/index',
],
],
];
21 changes: 0 additions & 21 deletions mod/search/start.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
*/
function search_init() {

// page handler for search actions and results
elgg_register_page_handler('search', 'search_page_handler');

// exclude /search routes from indexing
elgg_register_plugin_hook_handler('robots.txt', 'site', 'search_exclude_robots');

Expand All @@ -25,24 +22,6 @@ function search_init() {
elgg_register_plugin_hook_handler('view_vars', 'output/tag', 'search_output_tag');
}

/**
* Page handler for /search routes
*
* @param array $segments URL segments
*
* @return \Elgg\Http\OkResponse
* @throws SecurityException
*/
function search_page_handler($segments) {

if (!get_input('q') && isset($segments[0])) {
set_input('q', $segments[0]);
}

$output = elgg_view_resource('search/index');
return elgg_ok_response($output);
}

/**
* Exclude robots from indexing search pages
*
Expand Down
4 changes: 4 additions & 0 deletions mod/search/views/default/resources/search/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
// Search supports RSS
elgg_register_rss_link();

// This magic is needed to support /search/<query>
// but have /search/<query1>?q=<query2> as <query2> be the main search query
set_input('q', get_input('q', elgg_extract('route_query', $vars, null, false)));

$service = new \Elgg\Search\Search();
$params = $service->getParams();

Expand Down

0 comments on commit 6f085cd

Please sign in to comment.