Download & Extend

Fast fix to search path on submit when using i18n prefix

Project:Apache Solr Search Integration
Version:6.x-3.x-dev
Component:Miscellaneous
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs work

Issue Summary

Hi, i was having problems when i submit a keyword to search on the normal block search, i am using i18n prefix, the problem was that the prefix goes twice, i did a fast fix on apachesolr_search.module , function apachesolr_search_search_box_form_submit, adding this to line 826

if (!empty($language->language) && preg_match('/^\/' . $language->prefix . '\/?/', $path) > 0) {
$path = preg_replace('/^\/' . $language->prefix . '\/?/', '/', $path);
}

Comments

#1

I am having the same problem. Your fix works but you forgot to add:

global $language;

so total code is:

<?php
 
global $language;
  if (!empty(
$language->language) && preg_match('/^\/' . $language->prefix . '\/?/', $path) > 0) {
   
$path = preg_replace('/^\/' . $language->prefix . '\/?/', '/', $path);
  }
?>

add this at line 828 in latest dev version.

There must be a cleaner solution but I am glad it's fixed for now!

#2

Status:active» needs work

This seems a little similar to the base path issue.

Can you rewrite this code to be more similar to the following snippet?

$path = $form['#action'];
  // Create a regular expression string to find the base_path at the beginning
  // of the string.
  $base_path_regex = '#^' . base_path() . '#';
  // Find the base_path in the path()
  if (preg_match($base_path_regex, $path)) {
    // Replace the beginning of the string with nothing. The regular expression
    // avoids that we replace too much
    $path = preg_replace($base_path_regex, '', $path);
  }