Problem/Motivation

As discussed with borisson_ yesterday, I think that probably a common use case is to have a FacetSource block + facets and create a new route with Page Manager using parameters. For example /catalog/{tid}

With the current InboundPathProcessor for pretty paths, we only verify that a facet source (page) with the current requested route exists and then we remove the filters to obtain the base path. Here is the code from Drupal\facets_pretty_paths\PathProcessorPrettyPaths:

    // If path starts with an url having a facet source, reroute all subpaths to
    // the facet source.
    foreach ($facet_sources as $facet_source) {
      $facet_source_plugin = $facet_source_plugin_manager->createInstance($facet_source['id']);
      $facet_source_path = $facet_source_plugin->getPath();
      if ($path && strpos($path, $facet_source_path, 0) === 0) {
        $path = $facet_source_path;
      }
    }

Views would have the same problem AFAIK.

So actually a path like this http://example.com/catalog/856/size/107 generated by our UrlProcessor will give us a 404.

Proposed resolution

I would like to create a standard solution to detect if a page exists and then remove this part correctly using the InboundPathProcessor. My solution is to load all the pages and request for the parameters and the path(per page). Then obtain the path removing the filters.

But I have 3 things in mind:

1) Not sure if it would be very expensive to load all the pages (and Views ??)

2) I need to think in a correct pattern to check the path from page manager pages and detect the parameters and then remove the filters obtaining the correct base path.

3) Well a custom solution is always possible but I would like to contribute a standard solution if possible ;)

Opinions/help are welcome :)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

marthinal created an issue. See original summary.

marthinal’s picture

Title: Pretty Paths using page manager with parameters. » Pretty Paths for page manager routes with parameters.
StryKaizer’s picture

Not sure if I understand your solution.

Is it correct that you want to load all page manager pages which contain a facetsource view using facets pretty paths, and collect their paths?

If so, yes, that might work.
we could create a hook or plugin system to provide paths and facetsource combinations to pretty paths which will also trigger the system.
We can probably add some caching to that system, making it much faster, I am planning on adding a caching layer for the paths anyway (as I load every facetsource at the moment every cold request now, there's no reason to do this more then once).

StryKaizer’s picture

Status: Active » Postponed (maintainer needs more info)
marthinal’s picture

@StryKaizer sorry for the delay,

Is it correct that you want to load all page manager pages which contain a facetsource view using facets pretty paths, and collect their paths?

Yes that was the idea but I had no time to continue working on it.

marthinal’s picture

Version: » 8.x-1.x-dev
Status: Postponed (maintainer needs more info) » Needs work
Issue tags: +drupaldevdays
FileSize
3.29 KB
127.76 KB

I added the logic to verify if the current path is a page. We need to test routes with params.

marthinal’s picture

Assigned: Unassigned » marthinal
plopesc’s picture

Hey There!

marthinal’s picture

Status: Needs work » Needs review
FileSize
163.08 KB

Added regex to detect the paths with params.

Please give credit to @plopesc. He helped me with the regex. :)

marthinal’s picture

FileSize
3.41 KB

Here is the patch!

ilya.no’s picture

Thanks for the patch! While I worked with it, I faced with problem, described in this issue. So I had to re-worked the patch to include language fix into it as well. I'm not sure, if I should create new issue, so attaching patch here.

andypost’s picture

+++ b/src/PathProcessorPrettyPaths.php
@@ -32,4 +90,46 @@ class PathProcessorPrettyPaths implements InboundPathProcessorInterface {
+    $config = \Drupal::configFactory()->getEditable('language.negotiation');
+    $prefixes = $config->get('url.prefixes');

+++ b/src/Plugin/facets/url_processor/FacetsPrettyPathsUrlProcessor.php
@@ -16,23 +19,74 @@ use Symfony\Component\HttpFoundation\Request;
+    $config = \Drupal::configFactory()->getEditable('language.negotiation');
+    $prefixes = $config->get('url.prefixes');

do not use editable here

ilya.no’s picture

Thanks for the feedback. Attaching new patch.
I also faced following issue: I have search page with path '/search' and node view page with path '/node/{node}'. When I go to node adding page, e.g. '/node/add/article', then I'm redirected to 'node/add', because of getPageManagerPath() and preg_replace() inside it. I'm not sure, if this is common issue and about best way to solve it, so I've added additional if() condition inside 'if (preg_match($pm_path, $path, $matches)) {' and it works for me.

ilya.no’s picture

Updated patch with minor fix for comment of the constructor.

ilya.no’s picture

Added re-rolled patch against updated code of the module.

piggito’s picture

Patch has collision with #2924492: url_processor Not compatible with latest Facets UrlProcessorPluginBase

I'm adding a new patch combining last patch here and last one in conflict issue.

piggito’s picture

This portion of code is unnecessary since LanguageNegotion plugin already takes care of removing the language prefix. Moreover, it is causing issues since it considers paths starting by /{prefix} instead of /{prefix}/
Considering this I'm attaching a new patch removing this block and also the combined version to include #2924492: url_processor Not compatible with latest Facets UrlProcessorPluginBase

+    $language_prefix = $this->getLanguageUrlPrefix();
+    if (!empty($language_prefix) && strpos($path, $language_prefix) === 0 && $path != $language_prefix) {
+      $path = substr($path, strlen($language_prefix));
+    }
StryKaizer’s picture

Status: Needs review » Postponed (maintainer needs more info)

Can somebody confirm that this issue is still an issue?
We changed the routing internals in beta1, which could fix issues like this without extra code needed.

netdreamer’s picture

Yes @strykaizer, it seems to me that it is still needed: without it, with beta1 (and current dev) we are still getting 404 in the same situation (view for taxonomy with same "base" path as our faceted search).
But patch #17 cannot be applied anymore...

alesbencina’s picture

What is the situation with this module right now? is this working, I cant apply patch #17.

Upchuk’s picture

@alesbencina Please see the project page for updated info on development. If patches don't apply it means other work has gone and it no longer applies.

Is this still an issue? If so, please create a PR on github.

iyyappan.govind’s picture

Hi

I am using this module (version is 8.x-1.0-beta2). Have tested the following

Scenario 1:
1. Created FAQ page using view
2. Created Facet(Source is FAQ view page) and assigned the facet block in FAQ page.

FAQ page path - http:example.com/faq

I clicked the facet link and goes to http://example.com/faq/category/admissions. It shows page not found.

Scenario 2:
Created the landing page for FAQ page.
1. Created FAQ view block
2. Created facet using FAQ view block
3. Assigned above two blocks in panelizer.
Now, clicking the facet, it doesn't filter the result(Ajax). It is showing 404 while loading page.

Hope this helps.
Thanks

iyyappan.govind’s picture

Status: Postponed (maintainer needs more info) » Active
lukasss’s picture

There are also other modules that can use views for example LB, TVI ...