Problem/Motivation

A module defines a route at /example with _no_path: 'false'. Generating a link to that route with the fragment details produces #details. Following the link stays on the current page.

UrlGenerator::generateFromRoute() treats the non-empty string 'false' as true and returns only the query string and fragment. With unquoted false, it includes the route path.

The same problem affects _htmx_route. With _htmx_route: 'false', HtmxContentViewSubscriber::renderHtmxResponse() sends an ordinary HTML request through HtmxRenderer when the controller returns a render array. Opening the URL directly shows only the main content. With unquoted false, Drupal renders the full page.

Steps to reproduce

  1. In a test module, define a route named example.page with path /example and _no_path: 'false' under options. Rebuild caches.
  2. Call Url::fromRoute('example.page', [], ['fragment' => 'details'])->toString(). It returns #details.
  3. Set _no_path: false, rebuild caches and repeat. The URL now includes /example before the fragment.
  1. In Core's test_htmx module, set _htmx_route: 'false' on test_htmx.attachments.route_option and rebuild caches.
  2. Open /htmx-test-attachments/route-option directly. Only the main content appears.
  3. Repeat with unquoted false to see the full page.

Proposed resolution

Use BooleanRouteOption::get() from #3644412: [PP-1] Routing treats "false" as TRUE for _admin_route and no_cache in UrlGenerator::generateFromRoute() and HtmxContentViewSubscriber::renderHtmxResponse().

In UrlGeneratorTest, verify that _no_path: 'false' preserves the path. In HtmxRendererTest, verify that an ordinary request with _htmx_route: 'false' includes the “Powered by” block already placed by the test. In each case, expect a deprecation naming the option.

Remaining tasks

Postponed on #3644412: [PP-1] Routing treats "false" as TRUE for _admin_route and no_cache.

In Drupal 13: Track rejection of deprecated inputs in #3644403: [13.x] Reject deprecated non-boolean input in boolean config values.

User interface changes

None.

API changes

The _no_path and _htmx_route route options follow the boolean input rules from #3644412: [PP-1] Routing treats "false" as TRUE for _admin_route and no_cache. Use unquoted booleans in routing YAML and native booleans in PHP.

Data model changes

None.

Release notes snippet

The route options _no_path and _htmx_route now treat the deprecated string 'false' as FALSE.

Issue fork drupal-3644420

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pancho created an issue. See original summary.

pancho’s picture

Title: [PP-2] UrlGenerator omits the route path for _no_path: 'false' » [PP-2] _no_path and _htmx_route options enabled by 'false'
Issue summary: View changes
Related issues: +#3544632: Return only main content for endpoints designed to service htmx requests