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
- In a test module, define a route named
example.pagewith path/exampleand_no_path: 'false'underoptions. Rebuild caches. - Call
Url::fromRoute('example.page', [], ['fragment' => 'details'])->toString(). It returns#details. - Set
_no_path: false, rebuild caches and repeat. The URL now includes/examplebefore the fragment.
- In Core's
test_htmxmodule, set_htmx_route: 'false'ontest_htmx.attachments.route_optionand rebuild caches. - Open
/htmx-test-attachments/route-optiondirectly. Only the main content appears. - Repeat with unquoted
falseto 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
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
Comment #2
pancho