Problem/Motivation
Drupal core's tabledrag.js uses a hard-coded markup for the tabledrag toggle height markup and its wrapper div that are not overridable by themes.
Proposed resolution
- Introduce new Drupal.theme callback for the toggle weight (visibility) button.
- Introduce new Drupal.theme callback for the toggle button wrapper.
- Refactor
tabledrag.jsand fully replace the toggle if it is changed. This is required for adding different icons for the 'show' and the 'hide' action.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | 3084916-24.patch | 6.57 KB | bnjmnm |
| #24 | interdiff_20-24.txt | 326 bytes | bnjmnm |
| #20 | 3084916-20.patch | 6.56 KB | bnjmnm |
| #20 | interdiff_12-20.txt | 7.54 KB | bnjmnm |
| #16 | 3084916-16.patch | 5.89 KB | jpatel657 |
Comments
Comment #3
sibustephen commentedComment #4
sibustephen commentedAdding patch for Table Toggle handler which is now dynamic across -
Comment #5
lauriiiWe should also compile this file using the JavaScript compilation tools: https://www.drupal.org/node/2815083.
Why do we need the local variable here?
Comment #6
sibustephen commentedAdding patch for Table Toggle handler which is now dynamic across with both compiled and es6 file in es5 format as well - https://www.drupal.org/files/issues/2019-12-23/3084916-6-Add-a-new-drupa...
Comment #7
sibustephen commentedComment #10
bnjmnm#6 Took care of requirement #1, this takes care of the remaining requirements, #2 and #3.
Comment #11
lauriiiAny thoughts on making these just one theme function? It doesn't seem like we would necessarily need the level of flexibility to allow overriding them separately.
Comment #12
bnjmnm#11 sounds like a good idea. I was just doing a 1:1 relationship, but it is simpler with one theme function.
Comment #13
lauriiiShould we use the
data-drupal-selectorpattern which is getting more and more common place in core?Comment #14
nod_Need to update claro tabledrag too.
data-drupal-selector +1
There is an issue here. In case there are 2 tabledrag on the page:
Before
:
showColumnsupdate the button text for all tables on the pagehideColumnsupdate the button text for all tables on the pageAfter the patch
:
updateWeightToggle.updateWeightToggleremove all toggle buttons wrappers on the page (none),updateWeightToggle.updateWeightToggleremove all toggle buttons wrappers on the page (Table 1 toggle),showColumns=> executeupdateWeightToggle(see above)hideColumns=> executeupdateWeightToggle(see above)I would keep the existing behavior, Changing a text on all the tables toggle at once is already borderline, if one tabledrag object modify the html of other tables it's not acceptable. What would be better is react on the
columnschangeevent and have each object take care of updating it's toggle text.Comment #15
jpatel657 commentedComment #16
jpatel657 commentedas mention by lauriiii have added JS and generate patch
Comment #17
jpatel657 commentedComment #18
nod_#14 not addressed
Comment #19
bnjmnm@jpatel657 when you create a patch, an interdiff should also be included https://www.drupal.org/documentation/git/interdiff.
#16 looks like it may have been a mistake as there's no compiled JS and the only difference from #12 is adding the HTML markup for a weight toggle button to the div containing tabledrag warning messages. I think it would work best if the next patch builds on#12 so it's clearer from the interdiff what feedback is being addressed.
Comment #20
bnjmnmRe #14
This will be addressed in Claro in #3083051: Refactor tabledrag when core issues are resolved. This issue is one of several blockers for that issue.
This is a good point. The issue summary mentioned "fully replace the toggle" but it only needs to be possible to change the content of the toggle to get the desired flexibility. This approaches it per-table instead of globally and eliminates the need to add a new listener on each toggle.
Also adopted the data-drupal-selector suggested in #13
Comment #21
nod_Looks all good to me, if green RTBC
Comment #22
nod_Comment #23
lauriiiAny thoughts on calling the
toggleButtonContentinsidetableDragToggle? This would make it easy to add extra CSS classes to the button or the wrapper depending on whether the row weights are visible or not. We could use something like$.replaceWithfor replacing the old tabledrag button with the new one.Comment #24
bnjmnmThis takes care of #23.1. I'm less certain about #23.2, but it's possible I'm not fully understanding it. I like that the current approach does not require destroying/adding an event listener - but it's possible that isn't that big a deal or can actually be avoided.
Comment #25
nod_not a fan, this theme function is to initialize the markup not to update it whenever something changes. This can be done with the columnschange event when it's shown/hidden. Using replaceWith for an element that is by default the same in the prospect of someone using it differently in contrib feels wrong.
Unless there is a compelling argument that doing replaceWith allow something that is not possible with this I'd stick to the patch in it's current form.
Comment #26
lauriiiI don't feel too strongly about #23.2 so it seems fine to go with the current approach given that it's preferred by @bnjmnm and @nod_.
Let's still add a change record to describe the new theme functions.
Comment #27
bnjmnmAdded a CR https://www.drupal.org/node/3160782
Comment #28
lauriiiThank you for creating the CR! Looks great!
Committed 56aa632 and pushed to 9.1.x. Thanks!