diff --git a/project_issue.module b/project_issue.module index fc78330..4ff8bc3 100644 --- a/project_issue.module +++ b/project_issue.module @@ -1412,25 +1412,42 @@ function project_issue_query_result_links($project_arg = NULL) { global $user; $links = array(); + // @todo Ugly alert. It's kind of silly we include the 'advanced search' link + // on the advanced search page itself. But since we do, we don't want to + // convert the parameters in that case. Given how the rest of this works, we + // don't have a reliable way to know what page we're on, other than + // inspecting the current path. But we already assume below that the path will + // be project/issues/search for advanced search, so we might keep using that. + $parameters = drupal_get_query_parameters(); + $is_adv_search = strpos(current_path(), 'project/issues/search') === 0; + $search_parameters = _project_issue_convert_search_query($parameters, $is_adv_search); + if (empty($project_arg)) { // These are site-wide links, not per-project $links['create'] = project_issue_get_create_link(); $links['search'] = array( 'title' => t('Advanced search'), 'href' => "project/issues/search", - 'attributes' => array('title' => t('Use the advanced search page for finding issues.')), + 'query' => $search_parameters, + 'attributes' => array( + 'title' => t('Use the advanced search page for finding issues.'), + 'class' => ['no-issue-count'], + ), ); } else { // We know the project, make project-specific links. $project = project_load($project_arg); $machine_name = $project->field_project_machine_name[LANGUAGE_NONE][0]['value']; - $links['create'] = project_issue_get_create_link($project); $links['search'] = array( 'title' => t('Advanced search'), 'href' => "project/issues/search/$machine_name", - 'attributes' => array('title' => t('Use the advanced search page to find @project issues.', array('@project' => $project->title))), + 'query' => $search_parameters, + 'attributes' => array( + 'title' => t('Use the advanced search page to find @project issues.', array('@project' => $project->title)), + 'class' => ['no-issue-count'], + ), ); if ($user->uid) { $links['subscribe'] = array( @@ -1447,6 +1464,56 @@ function project_issue_query_result_links($project_arg = NULL) { } /** + * Converts regular search parameters to something suitable for advanced search. + * + * @param array $parameters + * The current query parameters. + * @param bool $is_advanced_search + * Are we already on the advanced search page or not? + * + * @return array + * The correct query parameters to use for advanced search. If we're already + * on advanced search, return whatever we were given. Otherwise, try to + * convert any parameters from the default issue views that are single value + * on regular search but multi-valued on advanced search into arrays. + */ +function _project_issue_convert_search_query($parameters, $is_advanced_search) { + if ($is_advanced_search) { + return $parameters; + } + $search_parameters = []; + foreach ($parameters as $key => $value) { + switch ($key) { + // This is the outlier, since it uses a different name in advanced search. + case 'category': + $search_parameters['categories'][] = $value; + break; + + // Although some sites (e.g. drupal.org) use 'categories' on regular + // search. So handle that here, too, just in case. + case 'categories': + case 'component': + case 'status': + case 'priorities': + case 'version': + case 'field_issue_version_value': + $search_parameters[$key][] = $value; + break; + + default: + // If we don't recognize it, pass it along as-is. + $search_parameters[$key] = $value; + break; + + } + } + + // Allow other modules to alter the advanced search parameters. + drupal_alter('project_issue_advanced_search_parameters', $search_parameters); + return $search_parameters; +} + +/** * Implement hook_preprocess_html(). * * Add the issue number to the node head title only.