Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add redirect to search page on 404 status #2576

Merged
merged 3 commits into from Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/dkan/dkan_sitewide/dkan_sitewide.blocks.inc
Expand Up @@ -491,7 +491,7 @@ function dkan_sitewide_dataset_search_form($form, $form_state) {
*/
function dkan_sitewide_dataset_search_form_submit($form, &$form_state) {
if ($query = $form_state['input']['search']) {
drupal_goto('dataset', array('query' => array('query' => $query)));
drupal_goto('search', array('query' => array('query' => $query)));

}
}
Expand Down
9 changes: 9 additions & 0 deletions modules/dkan/dkan_sitewide/dkan_sitewide.module
Expand Up @@ -266,6 +266,15 @@ function dkan_sitewide_preprocess_page(&$variables) {
if (isset($variables['is_front']) && $variables['is_front'] == TRUE) {
drupal_set_title('');
}
// Redirect 404 to search page.
$header = drupal_get_http_header("status");
if($header == "404 Not Found") {
$message = t('The page you requested does not exist or has moved. Try searching the site.');
drupal_set_message($message, 'status', FALSE);
$query = str_replace('/', ' ', $_SERVER['REQUEST_URI']);
unset($_GET['destination']);
drupal_goto('search', array('query' => array('query' => $query)));
}
}

/**
Expand Down
18 changes: 9 additions & 9 deletions test/features/search.feature
Expand Up @@ -8,14 +8,14 @@ Feature: Search
And pages:
| name | url |
| Dataset Search | /search/type/dataset |
| Dataset Results | /search/type/dataset?query=Dataset%2001 |
| Dataset Results | /search?query=Dataset%2001 |
| Topics Search | /search/field_topics |
| Topics Redirect | /topics |
| Not valid type search | /search/type/notvalid |
| Not valid tags search | /search/field_tags/notvalid |
| Not valid topics search | /search/field_topic/notvalid |
| Not valid resource search | /search/field_resources%253Afield_format/notvalid |
| Not valid license search | /search/field_license/notvalid |
| Not valid type search | /search?query=%20search%20type%20notvalid |
| Not valid tags search | /search?query=%20search%20field_tags%20notvalid |
| Not valid topics search | /search?query=%20search%20field_topic%20notvalid |
| Not valid resource search | /search?query=%20search%20field_resources%25253Afield_format%20notvalid |
| Not valid license search | /search?query=%20search%20field_license%20notvalid |
Given users:
| name | mail | roles |
| Badmin | admin@example.com | site manager |
Expand Down Expand Up @@ -59,8 +59,8 @@ Feature: Search
Scenario: See number of datasets on search page and Reset dataset search filters
Given I am on the "Dataset Search" page
When I search for "DKANTest"
Then I should see "2 results"
And I should see "2" items in the "datasets" region
Then I should see "4 results"
And I should see "4" items in the "datasets" region
When I press "Reset"
Then I should see all published search content

Expand Down Expand Up @@ -104,7 +104,7 @@ Feature: Search
@search_04
Scenario Outline: Forbid XSS injection in search
Given I am on the "<page>" page
Then I should see "Page not found"
Then I should see "No results were found. Please try another keyword."
Examples:
| page |
| Not valid type search |
Expand Down