I don't see a method nor a property for Request
on ControllerBase
. Am I missing something? Does this push us towards an argument resolver?
Thanks @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.
@nod_ My concern is about a conflict with the state stored in the form and the state stored in the request URL. Consider a form with an input A that responds to user interaction and sends the values in a get request.
Focusing only on values for clarity
- User sets A to 1
- The input regenerates, containing
data-hx-get="/path?A=1
Now if I set the value to 2 I am explicitly declaring that I will send 1. Isn't that confusing? It seems like the state encoded in the form should be the source of truth.
I have a concern with current url and query parameters.
If the form is using get, won’t the url for a new request contain the prior request parameters?
Problem/Motivation
Document how to implement ReplaceCommand using htmx
Proposed resolution
Document at https://www.drupal.org/docs/develop/drupal-apis/htmx/ajax-api-to-htmx/replacecommand →
Remaining tasks
Edit linked page and add documentation
User interface changes
None
Introduced terminology
None
API changes
None
Data model changes
None
Release notes snippet
None
Refactored the test to use a data provider.
fathershawn → changed the visibility of the branch 3546105-static-method to hidden.
We are adding these pages under https://www.drupal.org/docs/develop/drupal-apis/htmx/ajax-api-to-htmx → . I'm creating the child issues and standing up stub pages.
Added cross reference for how to return CSS.
Gitlab CI doesn't like MRs between issue branches:
Invalid version string "3546105-improve-url-management-dev"
but the kernel test passes locally.
Opened an MR with a working kernel test to your issue branch @nod_
Feedback addressed and all tests passing.
Made a couple of suggestions. I'll check back later to see if the unit test is running.
Yes - forms are also covered by this CR. We definitely plan to document each Ajax Command paired with an equivalent implementation using HTMX. There will be a documentation issue for each and a corresponding page.
For the CR you would would like an additional before? Something like:
Before (Ajax API)
$default_type = $form_state->getValue('config_type', $config_type);
$form['config_name'] = [
'#title' => $this->t('Configuration name'),
'#type' => 'select',
'#options' => $this->findConfiguration($default_type),
'#default_value' => $config_name,
'#prefix' => '<div id="edit-config-type-wrapper">',
'#suffix' => '</div>',
'#ajax' => [
'callback' => '::updateExport',
'wrapper' => 'edit-export-wrapper',
],
];
Would that be helpful?
I put up MR!13205. I discussed this idea with @nod_ in Slack. The static method makes creating or modifying the Url object relatively simple and the changes are fewer and easier to test.
Here's an example code block:
$url = Htmx::mainContentOnly(
Url::fromRoute('test_htmx.attachments.replace', [], $options)
);
$htmx = new Htmx();
$htmx->get($url);
All tests passing - only changes to the form. Existing test could remain in place because of HTMX detection added in 📌 Support dynamic forms using HTMX Active
Of course @kevinquillen. What questions did it leave you with or examples would you like?
We also have planned a whole set of documentation pages pairing Ajax API commands with how to accomplish that with these new tools.
fathershawn → changed the visibility of the branch 11.x to hidden.
fathershawn → made their first commit to this issue’s fork.
Yes - and there is another performance bottleneck when adding an AttributeValue class - cloning that object is expensive.
fathershawn → created an issue.
@ipumpkin That sounds like a bug. Please create a new issue related to this one. Please also give steps to reproduce the bug.
Thank you @webengr for your thoughtful comments. I did build and contribute this for the use case of the /donate
flow, generalized from something a client needed. I do have ideas for a more general version usable by site builders that I intend to get to out of my head and into code.
Tests adjusted and expanded based on feedback. All tests passing and ready for re-review.
fathershawn → created an issue.
Reviewed and confirmed. back to RTBC!
Updated the test based on review.
Updated based on latest review
fathershawn → changed the visibility of the branch 3522597-wrapper-format to hidden.
Moved how to handle routes/controllers built to service htmx requests to 📌 Return only main content for endpoints designed to service htmx requests Needs work . Reviewed with @nod_ this morning and this issue is now RTBC
fathershawn → created an issue.