Problem/Motivation
In \Drupal\Core\Render\Element\Actions::preRenderActionsDropbutton has a serious issue where it prematurely renders the buttons in an effort to "clone" them. This causes major issues when certain things are present on the button, like a #ajax or #attached, and effectively get lost because they're not part of the higher render root.
Also, there is @todo Move this to #pre_render in \Drupal\Core\Render\Element\Actions::getInfo which specifically refers to the above method. As it stands now, this method is actually only ever invoked if it's in a form (which in turn is invoked via #process).
Proposed resolution
Simply clone the button in question to the dropbutton render array and then set '#printed' => TRUE on the original element to effectively "hide" it.
Also, move the preRenderActionsDropbutton callback to an actual #pre_render callback.
Remaining tasks
Create patch- Create test
User interface changes
None
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #32 | interdiff_29-32.txt | 3.94 KB | sahil.goyal |
| #32 | 2855458-32.patch | 6.56 KB | sahil.goyal |
| #30 | 2855458-29.patch | 4.78 KB | nikhil_110 |
| #20 | 2855458-20.patch | 4.04 KB | quiron |
| #20 | interdiff_15_20.txt | 905 bytes | quiron |
Comments
Comment #2
markhalliwellComment #3
markhalliwellThis patch can be easily backported to prior versions as well.
Comment #4
markhalliwellComment #6
markhalliwellRandom test failures :-/Not random, bad function signature since it was moved to an actual
#pre_render.Comment #7
markhalliwellComment #8
markhalliwellTitle typo
Comment #9
joelpittetThank you for taking this on @markcarver. Just for context the @todo was from this issue #2326891: Convert system_element_info() to Element classes
Any ideas on how you'd like to test it? I'm guessing you found this during trying out #ajax on a drop button?
Comment #10
markhalliwellIdk, Drupal tests aren't really my thing.
Correct. The
#ajaxproperty never gets processed because:renderPlain) and all#attachedbubbled metadata is lost#pre_render" method is never invoked because it's actually defined as a#processcallbackComment #13
markhalliwellComment #15
MerryHamster commentedReroll patch from #7 for 8.7.x
Comment #16
MerryHamster commentedComment #18
savkaviktor16@gmail.com commentedComment #20
quironWith this few changes is passing the tests and working fine.
Comment #21
quironComment #22
eli-tIf we no longer refer to $button in this line, $button is never referenced after it is assigned. Therefore we should remove this variable. We can still call renderPlain() if we need the side effects, but there is no point assigning the return value to something we never use.
Comment #30
nikhil_110 commentedAttached patch against drupal 10.1.x
Comment #31
sahil.goyal commentedFixing CCF errors #30 update the patch and attaching the interdiff along.
Comment #32
sahil.goyal commentedUpdating patch again.