Error when added to 404 pages

Created on 26 October 2023, 11 months ago
Updated 6 September 2024, 1 day ago

Problem/Motivation

If the Views or the Exposed form is added to a 404 page it will return a Error.
The route will not load the 404 page.

Symfony\Component\Routing\Exception\ResourceNotFoundException: No routes found for "/a". in Drupal\Core\Routing\Router->matchRequest()

Steps to reproduce

Includes the Views with Better Exposed Filters on 404 page.

Proposed resolution

Similar issue with the Token module. See: https://www.drupal.org/project/token/issues/2969344 โ†’

Adds a try/catch to the Url::createFromRequest() on getExposedFormActionUrl() in src/Plugin/BetterExposedFiltersWidgetBase.php file.

๐Ÿ› Bug report
Status

Postponed: needs info

Version

7.0

Component

Code

Created by

๐Ÿ‡ง๐Ÿ‡ทBrazil adrianopulz Florianรณpolis

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

Merge Requests

Comments & Activities

  • Issue created by @adrianopulz
  • Assigned to Shreya_98
  • Merge request !49Resolve #3396769 "Error when added" โ†’ (Closed) created by Unnamed author
  • Issue was unassigned.
  • Status changed to Needs review 11 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Shreya_98

    Hi @adrianopulz,
    I have fixed this issue and also created MR for this issue . please replace The 'internal:/' URL is a reference to the internal path '/', which typically represents the homepage of your Drupal site. In other words, it's setting the fallback URL to the site's homepage.

    Thank you!

  • ๐Ÿ‡ง๐Ÿ‡ทBrazil adrianopulz Florianรณpolis

    Thanks for your fork @shreya_th!

    The problem is for URLs created from the Request, URLs from the route will not be a problem. You added try/catch to the URL created from the route when the display['display_options']['path'] is set. We need the fallback only in the createFromRequest() call.

    I've added a patch with the change example. I don't think we need to change the block of code using the UrlFromRoute.

  • Status changed to Needs work 5 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    What about other system paths?

  • Status changed to Postponed: needs info 5 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    That snippet of code has been removed in another fix. Can you confirm this is still an issue.

  • Status changed to Closed: outdated 4 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave
  • Status changed to Needs work 2 months ago
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands Johan den Hollander

    Hate to be reopening this issue, but the issue is still there using the latest 7.x release.

    We worked around the issue for now by modifying the code to be as follows:

    use Symfony\Component\Routing\Exception\ResourceNotFoundException;
    
    protected function getExposedFormActionUrl(FormStateInterface $form_state): Url {
        $request = \Drupal::request();
        try {
          $url = Url::createFromRequest(clone $request);
          $url->setAbsolute();
          return $url;
        }
        catch (ResourceNotFoundException $e) {
          return Url::fromRoute('<front>')->setAbsolute();
        }
      }

    A patch will follow, I expect this code needs some better attention.

  • ๐Ÿ‡จ๐Ÿ‡พCyprus Alex Bukach

    Alex Bukach โ†’ made their first commit to this issueโ€™s fork.

  • Merge request !86Handled non-existent routes โ†’ (Open) created by Alex Bukach
  • Status changed to Needs review 2 months ago
  • ๐Ÿ‡จ๐Ÿ‡พCyprus Alex Bukach

    Created MR!86, here's the respective patch.

  • Pipeline finished with Success
    2 months ago
    Total: 229s
    #215069
  • Status changed to Needs work 2 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    MR should be against 7.0.x but letโ€™s add test coverage also

  • Status changed to Postponed: needs info 10 days ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Could the steps be flushed out.

    I added a view block that's used better exposed filters to 404 page and not getting any error.

    On 10.3

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland idflood

    I've got the same issue. I've defined a global "search" exposed form in block, which is added to the header of the website. Then on all 404 pages it shows the same error.

    I've tried the patch in #12 and it went nicely, even if I'm still using the 6.x version. The patch fixed the issue, at least there is now no more errors.

Production build 0.71.5 2024