New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH Return PJAX responses from gridfield edit forms #11206
ENH Return PJAX responses from gridfield edit forms #11206
Conversation
Note that while this is being implemented to facilitate fixing a bug, the approach is somewhat more risky in terms of chance of regressions than I feel comfortable with in a patch release - hence targeting |
@@ -170,7 +171,7 @@ public function edit($request) | |||
])->renderWith($this->getTemplates()); | |||
|
|||
if ($request->isAjax()) { | |||
return $return; | |||
return $this->getResponseNegotiator($return)->respond($request); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing this here means it applies for the save and publish actions, with a relatively low chance of affecting custom actions people add.
I went with this approach because admin uses PJAX for the form submission and elemental expects a PJAX response in return. It doesn't make a distinction between different admin sections or different contexts for the form, nor should it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also and admin behat failure on the sink run https://github.com/creative-commoners/recipe-kitchen-sink/actions/runs/8808259049/job/24177023040 - I've tried rerunning once though the same error has appeared so it's probably legit
* https://html.spec.whatwg.org/#the-script-element | ||
* See LeftAndMain::prepareDataForPjax() | ||
*/ | ||
private function prepareDataForPjax(array $data): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code duplication with LeftAndMain::prepareDataforPjax() - it would make sense to make this a protected method on RequestHandler and remove it from LeftAndMain and here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point, I've moved it - there's another PR now for admin where it gets removed from LeftAndMain
.
Note that until that's merged, CI will fail because of the mismatch in method signatures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK - since the linked sink PR on the parent issue is currently red, it probably makes sense to redo the sink PR with the new admin PR included
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That failure is expected - there's a note about it right next to the link to the CI run. But for the sake of avoiding ping pong I'll update the CI run to include the new admin PR.
private function getResponseNegotiator(DBHTMLText $renderedForm): PjaxResponseNegotiator | ||
{ | ||
return new PjaxResponseNegotiator([ | ||
'Default' => function () use ($renderedForm) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this is correct? LeftAndMain::getResponseNegotiator() has a 'default' key instead (lowercase)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, fixed
9f41d45
to
e830c51
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally, works good. CI failures are expected
Description
Adds a PJAX response negotiator to
GridFieldDetailForm_ItemRequest
so that javascript which is expecting PJAX responses will get what it's expecting.Note there's a kitchen sink CI run linked in the main issue
Manual testing steps
silverstripe/frameworktest
to a project and make sure all of the operations work as expected for companies (which are versioned) and employees (which are not versioned) in "Test ModelAdmin"Company
class (yml config snippet below), add a block with an upload field (e.gsilverstripe/elemental-fileblock
) and make sure you can upload a file to the block and save with the page save button.Issues
UploadField
inside inline-editable element doesn't update when saving parent record in aGridFieldDetailForm
silverstripe-elemental#1156