Closed (fixed)
Project:
Drupal core
Version:
11.x-dev
Component:
ajax system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
2 Sep 2025 at 20:05 UTC
Updated:
28 Oct 2025 at 05:29 UTC
Jump to comment: Most recent
Comments
Comment #2
fathershawnComment #3
fathershawnComment #4
richgerdes@fathershawn,
Per our conversation at DrupalNYC Contribution day, i think it would be helpful to have a trait to parse the request headers. Something like...
These functions can look for the request ($this->request ?: \Drupal->getRequest()) and then get the headers.
We also talked about the helpfulness of a
getHtmxTriggerElement($build): ?arrayfunction which could locate the render element and to allow access to properties or data, but decided this wasn't critical at this time.Comment #5
fathershawnComment #6
fathershawnComment #7
larowlanWould the primary use case for this be in controllers and form builders?
In which case I think a trait and adding that trait to FormBase and ControllerBase (that already have the request) feels reasonable.
The alternative is we add a new argument resolver to
http_kernel.controller.argument_resolverand a HtmxHelper value object that can resolve from the current request.That would allow people to typehint their controllers with `HtmxHelper $helper` and it would magically resolve like you can do for Request.
Comment #8
fathershawnThanks @larowan. That's +2 for a trait, plus where to start with it in core! I think the trait is easier for contrib developers to understand who might be doing something of controller/form context. Controller/form will be a 90% use case I bet.
Comment #9
fathershawnComment #10
fathershawnI don't see a method nor a property for
RequestonControllerBase. Am I missing something? Does this push us towards an argument resolver?Comment #11
fathershawnComment #13
fathershawntest is passing
Comment #14
fathershawnComment #15
fathershawnComment #16
smustgrave commentedLeft some minor comments on the MR.
Comment #17
fathershawnComment #18
nicxvan commentedTwo questions on the MR.
I the plan to introduce the trait here and then add it to form and controller etc later?
Can we create follow ups for those with some notes for how to test it in deeper requests?
Comment #19
fathershawn@nicxvan The plan for this MR is to add the trait and then include the trait in the
FormBaseclass. We are not adding it to the ControllerBase in core because of concerns about BC but it could then be added to specific controllers as appropriate.Comment #20
nicxvan commentedI think this is good, @fathershawn pointed out I missed this was already added to FormBase
Comment #21
larowlanJust one comment on the MR, fine to self RTBC after that I think
Comment #22
fathershawnMarking RTBC after implementing the test change from @larowan as he suggested. All tests passing
Comment #25
nod_Hey a HTMX issue I can commit, yay!
Committed 5edaa75 and pushed to 11.x. Thanks!