Use of this module and "facets_pretty_paths" may lead to unwanted substitutions

Created on 15 May 2024, 7 months ago

Problem/Motivation

When using the "facets_pretty_paths" module, I notice that a specific problem occurs when the URL also contains part of another URL alias and replaces it.

This results in:
/nieuws (/news) => view for news
/zoeken (/search) => view for search
/zoeken/type/news => view plus facet filter

Both "nieuws" (=>nieuws) and "zoeken" (=>search) have a translated URL alias.

However, it replaces "news" and not "search" which results in:
/search/type/nieuws

This is undesirable, the URL alias is not translated and the filter no longer works.

Steps to reproduce

I follow the steps as described in:
https://www.drupal.org/project/tvp/issues/3342716 🐛 The getInboundPath should only work for the request path Fixed

Proposed resolution

I'm adding a patch to this ticket with a possible fix

Remaining tasks

Can the proposed solution be thoroughly examined?

🐛 Bug report
Status

Active

Version

1.1

Component

Code

Created by

🇧🇪Belgium wouter.h

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @wouter.h
  • 🇧🇪Belgium wouter.h

    My solution ensures that in the "strReplaceFirst" function it specifically searches for a URL alias that starts with a part instead of the first occurring part in the URL.

      private function strReplaceFirst(string $search, string $replace, string $subject) {
        if(str_starts_with($subject, $search)) {
          $pos = strpos($subject, $search);
          if ($pos !== false) {
            return substr_replace($subject, $replace, $pos, strlen($search));
          }
        }
    
        return $subject;
      }
    

    After checking, I notice that it no longer replaces the news part of the "facets_pretty_paths" module, but the effective first part of the URL remains untranslated.

    "/search/type/news" should be "/search/type/news"

    After removing the "break;" in the "getOutboundPath" function everything works as expected

Production build 0.71.5 2024