Searching for "foo/bar" generates an error:

Symfony\Component\Routing\Exception\InvalidParameterException: Parameter "keys" for route "search_api_page.sv.personal" must match "[^/]++" ("foo / bar" given) to generate a corresponding URL. in Drupal\Core\Routing\UrlGenerator->doGenerate() (line 194 of core/lib/Drupal/Core/Routing/UrlGenerator.php).

Drupal\Core\Routing\UrlGenerator->getInternalPathFromRoute('search_api_page.sv.personal', Object, Array, Array) (Line: 308)
Drupal\Core\Routing\UrlGenerator->generateFromRoute('search_api_page.sv.personal', Array, Array, 1) (Line: 105)
Drupal\Core\Render\MetadataBubblingUrlGenerator->generateFromRoute('search_api_page.sv.personal', Array, Array, ) (Line: 749)
Drupal\Core\Url->toString() (Line: 130)
Drupal\Core\Form\FormSubmitter->redirectForm(Object) (Line: 77)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 583)
Drupal\Core\Form\FormBuilder->processForm('search_api_page_block_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm('search_api_page_block_form', Object) (Line: 212)
Drupal\Core\Form\FormBuilder->getForm('Drupal\search_api_page\Form\SearchApiPageBlockForm', Array) (Line: 53)
Drupal\kau_solr\Controller\KauSolrSearchApiPageController->page(Object, 'personal', '')
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 572)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 139)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 62)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 98)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 77)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 626)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jseffel created an issue. See original summary.

swentel’s picture

Mmm yeah, there's probably not a (clean) way to get this working when clean urls is enabled, unless I add more parts to the path when generating the route.

mr.baileys’s picture

Proof of concept attached, probably needs some serieus testing, cleanup and fine-tuning, but overall it seems to work and is not too hackish. Needs review for approach.

sawtell’s picture

I don't have any experience with PathProcessors so can't comment on that specifically but the patch is working for me.

borisson_’s picture

Status: Needs review » Needs work

This looks good, but I have some nits to pick.

  1. +++ b/search_api_page.services.yml
    @@ -0,0 +1,6 @@
    +        - { name: path_processor_inbound, priority: 300 }
    \ No newline at end of file
    

    Needs new blank line.

  2. +++ b/src/PathProcessor/PathProcessorSearchApiPage.php
    @@ -0,0 +1,84 @@
    +
    +class PathProcessorSearchApiPage implements \Drupal\Core\PathProcessor\InboundPathProcessorInterface {
    

    Needs a class docblock. I think we can also import the InboundPathProcessorInterface to make this line < 80 chars.

  3. +++ b/src/PathProcessor/PathProcessorSearchApiPage.php
    @@ -0,0 +1,84 @@
    +  public function __construct(EntityTypeManagerInterface $entityTypeManager, LanguageManagerInterface $languageManager, ConfigFactoryInterface $config) {
    

    I think these also need a docblock.

    /**
     * The class constructor
     *
     * @param...
    
  4. +++ b/src/PathProcessor/PathProcessorSearchApiPage.php
    @@ -0,0 +1,84 @@
    +  public function processInbound($path, Request $request) {
    

    Needs a docblock.

  5. +++ b/src/PathProcessor/PathProcessorSearchApiPage.php
    @@ -0,0 +1,84 @@
    +    return $path;
    

    This is what happens when nothing matches, right? Would it make sense to document that?

  6. +++ b/src/PathProcessor/PathProcessorSearchApiPage.php
    @@ -0,0 +1,84 @@
    +  protected function getSearchApiPagePathsUsingCleanUrls() {
    

    Let's give this a docblock as well.

    I also think we can refactor this method to be a little bit easier. But that's interpretation/taste. Can be left alone I think.

    
    $pages = array_filter($pages, function($i) {
      return $i->getCleanUrl();
    });
    
    // Pseudocode w/ changed flow.
    foreach ($pages as $page) {
    if (!$is_multilingual) {
      $paths[] = '/' . $page->getPath();
    }
    else {
      foreach(->getLanguages as $language) {
      $pathOverride = $this->...->get('path');
    
    $paths[] = $pathOverride ?: $path
    }
    }
    }
    
    
  7. +++ b/src/PathProcessor/PathProcessorSearchApiPage.php
    @@ -0,0 +1,84 @@
    +}
    \ No newline at end of file
    

    Needs newline.

borisson_’s picture

Do you think we should keep this as a seperate service or should we integrate this with #2794119: Wrong URL on language switcher block?

borisson_’s picture

Fixed my own comments + added a test.

borisson_’s picture

FileSize
5.11 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 8: 2721619.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

borisson_’s picture

This breaks the tests added in #2904203: Spaces in searchs cause AliasManager to throw errors., so we need to fix this to still pass with those tests added.

borisson_’s picture

Status: Needs work » Needs review
FileSize
2.23 KB
5.16 KB

I fixed this, and now the previous tests also passes. This is the only significant change.

-        return $search_api_clean_url_path . urlencode($keys);
+        return $search_api_clean_url_path . rawurlencode($keys);

I made some other changes, such as indenting the yaml correctly, and I moved one getter out of the foreach, for some better performance. This is probably just a few ms, because otherwise this was coming from a static cache - but I guess even just a function call can make a small difference.

All we need is a +1, so we can get this in.

  • borisson_ committed d9793f2 on 8.x-1.x
    Issue #2721619 by borisson_, mr.baileys: Searching breaks when user...
borisson_’s picture

Status: Needs review » Fixed

Committed this, we have a test that proves this works.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.