Problem/Motivation
Dropbutton / Operations groups a set of links rendered as a drop-down button.
However, in some cases, we need to add Button (Submit) elements to Dropbutton:
- Form Actions has a process callback
::preRenderActionsDropbuttonthat converts its children to Dropbutton, but it's a fragile and broken workaround #2855458: Action dropbuttons are prematurely rendered and available only in #process that works only inside a form actions, obviously. - Views UI has to mimic Dropbutton markup in
ViewEditForm::getDisplayDetailsby using ugly#prefixes,#suffixes and#markups that basically hard-codes a non-overridable core template (without attaching the dropbutton library) and makes maintenance / theming much harder.
Proposed resolution
Provide a way to add Button (or Submit) elements to Dropbutton.
Remaining tasks
Patch.
User interface changes
Nothing.
API changes
@todo
Data model changes
@todo
Release notes snippet
@todo
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3057577-add-buttons-to-dropdown-2.patch | 2.75 KB | quiron |
Comments
Comment #2
quironI guess something similar to what is done in actions when https://www.drupal.org/project/drupal/issues/2855458 is done will work here. If is ok maybe we should look for a better location for the shared code between both methods.
Comment #3
lauriiiComment #4
wim leers#type ⇒ 'button'uses!🤔 I think this took inspiration from
\Drupal\Core\Render\Element\Actions::preRenderActionsDropbutton(). Let's add an@seeto ensure that we keep them in sync.🤔 Why do we even need to keep the original?
Comment #6
huzookaRe #2:
How can a Button element have child elements? (I think that it cant have at all).
The only place where core tries to hack
<input type="submit"/>s in a Dropbutton is the ViewsEditForm (I referenced that in the issue summary), and I'm using that for testing our options and even this patch.The hack starts there at line 403 and ends at line 511. If you check the code, you will see that the
pathkey is a link and not an input submit. So the ideal Dropbutton must be able to render links, Buttons and Submit elements, even mixed.And even contrib modules do that (at least Paragraphs does that, see #3079128: Broken Dropdown prevents Save in Claro).
Since Dropbutton uses the links theme function, these are hacks now, and this kind of hacks are not acceptable imho.
Comment #7
lauriiiComment #9
bnjmnmThe Splitbutton element will be capable of this, and is nearing completion in #1899236: Add new Splitbutton render element to eventually replace Dropbutton. It will be very easy to change dropbuttons to splitbuttons.
As @huzooka already stated in #6, making this possible in a dropbutton would either require something quite hacky or a major API change that is far more complex than simply changing to Splitbutton once available.
Comment #10
damienmckennaThank you so much for the update!