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

  1. Introduce new Drupal.theme callback for the toggle weight (visibility) button.
  2. Introduce new Drupal.theme callback for the toggle button wrapper.
  3. Refactor tabledrag.js and 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

Comments

huzooka created an issue. See original summary.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

sibustephen’s picture

Assigned: Unassigned » sibustephen
sibustephen’s picture

Adding patch for Table Toggle handler which is now dynamic across -

lauriii’s picture

Status: Active » Needs work
  1. --- a/core/misc/tabledrag.es6.js
    +++ b/core/misc/tabledrag.es6.js
    

    We should also compile this file using the JavaScript compilation tools: https://www.drupal.org/node/2815083.

  2. +++ b/core/misc/tabledrag.es6.js
    @@ -210,7 +210,7 @@
    +      const tableToogleweight = Drupal.theme('tableToogleweight');
    

    Why do we need the local variable here?

sibustephen’s picture

Adding 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...

sibustephen’s picture

Assigned: sibustephen » Unassigned
Status: Needs work » Needs review

Status: Needs review » Needs work

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

bnjmnm’s picture

Status: Needs work » Needs review
StatusFileSize
new8.55 KB
new8.29 KB

#6 Took care of requirement #1, this takes care of the remaining requirements, #2 and #3.

lauriii’s picture

Any 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.

bnjmnm’s picture

StatusFileSize
new6.67 KB
new5.52 KB

#11 sounds like a good idea. I was just doing a 1:1 relationship, but it is simpler with one theme function.

lauriii’s picture

Issue tags: +JavaScript
+++ b/core/misc/tabledrag.es6.js
@@ -1707,6 +1716,18 @@
+        `<div class="tabledrag-toggle-weight-wrapper" data-drupal-tabledrag-toggle-weight-wrapper><button type="button" class="link tabledrag-toggle-weight" data-drupal-tabledrag-toggle-weight>${text}</button></div>`,

Should we use the data-drupal-selector pattern which is getting more and more common place in core?

nod_’s picture

Status: Needs review » Needs work

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

:

  1. Table 1 processed: The button is created and added before the table element in the constructor for Table 1.
  2. Table 2 processed: The button is created and added before the table element in the constructor for Table 2.
  3. When columns are shown showColumns update the button text for all tables on the page
  4. When columns are hidden hideColumns update the button text for all tables on the page

After the patch

:

  1. Table 1 processed: initialize the column visibility of Table 1 => execute updateWeightToggle.
    1. updateWeightToggle remove all toggle buttons wrappers on the page (none),
    2. select all the tables that have been 'onced' by tabledrag (here Table 1) and recreate the html + insert before each table
    3. bind the event listener on all toggle buttons on the page (for Table 1).
  2. Table 2 processed: initialize the column visibility of Table 2 => execute updateWeightToggle.
    1. updateWeightToggle remove all toggle buttons wrappers on the page (Table 1 toggle),
    2. select all the tables that have been 'onced' by tabledrag (here Table 1 and Table 2) and recreate the html + insert before each table
    3. bind the event listener on all toggle buttons on the page (for Table 1 and Table 2).
  3. When columns are shown showColumns => execute updateWeightToggle (see above)
  4. When columns are hidden hideColumns => execute updateWeightToggle (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 columnschange event and have each object take care of updating it's toggle text.

jpatel657’s picture

Assigned: Unassigned » jpatel657
Status: Needs work » Active
jpatel657’s picture

Status: Active » Needs review
Issue tags: +Trigyn-WeeklyCodeSprint
StatusFileSize
new5.89 KB

as mention by lauriiii have added JS and generate patch

jpatel657’s picture

Assigned: jpatel657 » Unassigned
nod_’s picture

Status: Needs review » Needs work

#14 not addressed

bnjmnm’s picture

@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.

bnjmnm’s picture

StatusFileSize
new7.54 KB
new6.56 KB

Re #14

Need to update claro tabledrag too.

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.

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 columnschange event and have each object take care of updating it's toggle text.

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

nod_’s picture

Status: Needs work » Needs review

Looks all good to me, if green RTBC

nod_’s picture

Status: Needs review » Reviewed & tested by the community
lauriii’s picture

Status: Reviewed & tested by the community » Needs review
  1. +++ b/core/misc/tabledrag.es6.js
    @@ -171,6 +171,11 @@
    +    /**
    +     * @type {jQuery}
    +     */
    +    this.$toggleWeightButton = null;
    
  2. We should probably make it explicit that this property is nullable.
    +++ b/core/misc/tabledrag.es6.js
    @@ -1707,6 +1712,29 @@
    +      tableDragToggle: () =>
    ...
    +      toggleButtonContent: show =>
    

    Any thoughts on calling the toggleButtonContent inside tableDragToggle? 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 $.replaceWith for replacing the old tabledrag button with the new one.

bnjmnm’s picture

StatusFileSize
new326 bytes
new6.57 KB

This 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.

nod_’s picture

Status: Needs review » Reviewed & tested by the community

Any thoughts on calling the toggleButtonContent inside tableDragToggle? 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 $.replaceWith for replacing the old tabledrag button with the new one.

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.

lauriii’s picture

Issue tags: +Needs change record

I 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.

bnjmnm’s picture

lauriii’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs change record

Thank you for creating the CR! Looks great!

Committed 56aa632 and pushed to 9.1.x. Thanks!

  • lauriii committed 56aa632 on 9.1.x
    Issue #3084916 by bnjmnm, sibustephen, lauriii, nod_: Add a new Drupal....

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.