Problem/Motivation

Part of effort to deprecate procedural code in:

Proposed resolution

  • Move drupal_attach_tabledrag() functionality to \Drupal\Core\Render\Element\Table form element class as a public static method.
  • Deprecate drupal_attach_tabledrag()

Usage in contrib is http://grep.xnddx.ru/search?text=drupal_attach_tabledrag

Remaining tasks

review/commit

User interface changes

None.

API changes

  • New public static method on \Drupal\Core\Render\Element\Table::attachTabledrag() form element.
  • drupal_attach_tabledrag() is deprecated.
  • internal element selector changed to use data-drupal-tabledrag attribute instead of HTML ID (used only internally)

Data model changes

None.

Release notes snippet

N/A.

Issue fork drupal-3035343

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

claudiu.cristea created an issue. See original summary.

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

Issue summary: View changes
andypost’s picture

Status: Active » Needs review
StatusFileSize
new10.53 KB

Initial patch, it needs to get rid of drupal_static() inside, fix docs usage and file CR

andypost’s picture

StatusFileSize
new10.21 KB
new16.48 KB

Added cr, fixed docs, added test

The last submitted patch, 4: 3035343-4.patch, failed testing. View results

claudiu.cristea’s picture

+++ b/core/lib/Drupal/Core/Render/Element/Table.php
@@ -388,11 +395,164 @@ public static function preRenderTable($element) {
+        self::attachTabledrag($element, $options);

+++ b/core/modules/field_ui/src/Element/FieldUiTable.php
@@ -116,7 +117,7 @@ public static function tablePreRender($elements) {
+        self::attachTabledrag($elements, $options);

What if someone wants to extend this class by providing its own ::attachTabledrag() method? He/she will be forced to copy also the calling code. Wouldn't it be better to use static::?

Some may argue against the new Table public static method. But I don't see a good reason why we cannot add it. Of course we can move it to a helper class, something like a component, but stil...

andypost’s picture

@claudiu.cristea I think the same way about static vs self but self works the same way here https://3v4l.org/6p6kv

mcannon’s picture

Status: Needs review » Reviewed & tested by the community

The patch applied cleanly & I thoroughly tested core forms that use the table drag behavior such as Views UI, User Roles & Block Layout.

As for the topic about making this extendable with "static::" instead of "self::", I can agree with that statement, but I question the need to make Table Drag extendable. In 9 years of drupal development, I cannot think of a use case that required changing the basic behavior of table drag. Although, if the goal is to make every little piece of core extendable and "self::" requires duplicating code to extend, then it might need to be changed.

While writing this, I saw @andypost stated "static::" and "self::" are behaving the same so I believe this is good as is.

claudiu.cristea’s picture

Status: Reviewed & tested by the community » Needs work

@claudiu.cristea I think the same way about static vs self but self works the same way here https://3v4l.org/6p6kv

Well, they are not the same. I think I wasn't very clear in my explanation. See https://3v4l.org/UUFQF to understand how they are different. In this example the parent printWithSelf() cannot be reused because will always refer the parent getText(). So, ExtendedClass will have to extend printWithSelf() too. Not the case of printWithStatic().

This is also a good reference http://php.net/manual/en/language.oop5.late-static-bindings.php

andypost’s picture

Status: Needs work » Needs review

@claudiu.cristea I understand your example but as I said it depends on usage of static protected variable but not the class method

I mean that if extendend class needs to override method but keep counter the same is one case, but other case if it need own counter

andypost’s picture

Issue summary: View changes

Added contrib usage (not huge) to summary http://grep.xnddx.ru/search?text=drupal_attach_tabledrag

claudiu.cristea’s picture

@andypost, sorry, you don't understand my point. It's not about the static protected variable, it's not about the counter. I'm repeating It's about when somebody wants to extend ONLY ::attachTabledrag(). Then he/she will write a class like this:

use Drupal\Core\Render\Element\Table;

class MyTable extends Table {
  public static function attachTabledrag(&$element, array $options) {
    // A custom implementation.
  }
}

But with #5 we force him/her duplicate the code from preRenderTable() in the new class, so his class, instead of being simple as above, will look in this way:

use Drupal\Core\Render\Element\Table;

class MyTable extends Table {
  public static function attachTabledrag(&$element, array $options) {
    // A custom implementation.
  }
  public static function preRenderTable($element) {
    // A 100% copy of the parent preRenderTable() === CODE DUPLICATION!
  }
}

claudiu.cristea’s picture

Status: Needs review » Needs work

Nits:

  1. +++ b/core/lib/Drupal/Core/Render/Element/Table.php
    @@ -85,9 +92,9 @@ public function getInfo() {
    +      // @see Table::attachTabledrag()
    
    @@ -328,14 +335,14 @@ public static function validateTable(&$element, FormStateInterface $form_state,
    +   * @see attachTabledrag()
    

    One has a non-namespaced class name, the other is only the method name. Let's write both with the full-qualified class namespace.

  2. +++ b/core/lib/Drupal/Core/Render/Element/Table.php
    @@ -388,11 +395,164 @@ public static function preRenderTable($element) {
    +   * themed into a table. The table must have an ID attribute set and it
    +   * may be set as follows:
    

    Words "may be" can go one line up.

  3. +++ b/core/lib/Drupal/Core/Render/Element/Table.php
    @@ -388,11 +395,164 @@ public static function preRenderTable($element) {
    +   * See MenuForm::BuildOverviewForm for an example creating a table
    +   * containing parent relationships.
    

    Word "containing" should go one line up.

  4. +++ b/core/lib/Drupal/Core/Render/Element/Table.php
    @@ -388,11 +395,164 @@ public static function preRenderTable($element) {
    +   *   - 'table_id': String containing the target table's id attribute.
    +   *     If the table does not have an id, one will need to be set,
    +   *     such as <table id="my-module-table">.
    

    Words "If the" should go one line up. After that, aslo "such as".

  5. +++ b/core/lib/Drupal/Core/Render/Element/Table.php
    @@ -388,11 +395,164 @@ public static function preRenderTable($element) {
    +   *   - 'relationship': String describing where the "action" option
    +   *     should be performed. Either 'parent', 'sibling', 'group', or 'self':
    

    Also "should be" goes 1 line up.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new3.54 KB
new16.52 KB

Addressed all comments

andypost’s picture

+++ b/core/lib/Drupal/Core/Render/Element/Table.php
@@ -342,7 +342,7 @@ public static function validateTable(&$element, FormStateInterface $form_state,
-   * @see attachTabledrag()
+   * @see \Drupal\Core\Render\Element\Table::attachTabledrag()

btw checked phpdoc and found no strong suggestion about using FQDN for that but it looks really better

claudiu.cristea’s picture

Nice!

+++ b/core/modules/field_ui/src/Element/FieldUiTable.php
@@ -116,7 +117,7 @@ public static function tablePreRender($elements) {
+        self::attachTabledrag($elements, $options);

Looks like this was left out.

andypost’s picture

StatusFileSize
new668 bytes
new16.52 KB

oh, yep

claudiu.cristea’s picture

Status: Needs review » Reviewed & tested by the community

Great!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 18: 3035343-18.patch, failed testing. View results

andypost’s picture

Status: Needs work » Reviewed & tested by the community

Queued retest, looks Drupal\Tests\media\FunctionalJavascript\MediaStandardProfileTest has random failures

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 18: 3035343-18.patch, failed testing. View results

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new16.54 KB
andypost’s picture

Status: Needs review » Reviewed & tested by the community

back to rtbc

catch’s picture

Status: Reviewed & tested by the community » Needs review

Partly out of scope here since it's a conversion, but partly not because moving to the static class property emphasises the problem.

We've been moving away from incremented HTML IDs because they don't work for AJAX responses anyway, such as #1305882: drupal_html_id() considered harmful; remove ajax_html_ids to use GET (not POST) AJAX requests and #1090592: [meta] Use HTML5 data-drupal-* attributes instead of #ID selectors in Drupal.settings. Seems like the issue affects tabledrag as much as any other HTML ID.

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

claudiu.cristea’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update, +Needs change record updates

(...) Seems like the issue affects tabledrag as much as any other HTML ID.

@catch, then we should rescope this issue. Needs IS and CR update.

+++ b/core/includes/common.inc
@@ -721,35 +722,15 @@ function drupal_process_states(&$elements) {
+ * @deprecated in Drupal 8.7.0 and will be removed in Drupal 9.0.0. Use
...
+  @trigger_error('drupal_attach_tabledrag() is deprecated in Drupal 8.7.0 and will be removed in Drupal 9.0.0. Use \Drupal\Core\Render\Element\Table::attachTabledrag() instead. See https://www.drupal.org/node/3035565', E_USER_DEPRECATED);

+++ b/core/tests/Drupal/KernelTests/Core/Render/RendererLegacyTest.php
@@ -37,4 +38,23 @@ public function providerAttributes() {
+   * @expectedDeprecation drupal_attach_tabledrag() is deprecated in Drupal 8.7.0 and will be removed in Drupal 9.0.0. Use \Drupal\Core\Render\Element\Table::attachTabledrag() instead. See https://www.drupal.org/node/3035565

Let's move to Drupal 8.8.0. Also the CR https://www.drupal.org/node/3035565 needs update.

andypost’s picture

StatusFileSize
new2.19 KB
new16.52 KB

Fix message

finnsky’s picture

Status: Needs work » Needs review
StatusFileSize
new19.41 KB
new3.62 KB

Updated patch js with data-drupal-tabledrag-id attribute as mentioned in #25

Status: Needs review » Needs work

The last submitted patch, 29: 3035343-29.patch, failed testing. View results

finnsky’s picture

seems tests should be updated aswell

andypost’s picture

StatusFileSize
new347 bytes
new19.08 KB
new28.85 KB
new29.96 KB
new17.72 KB

The book ordering is broken because of weight processed wrong

Now it looks like

HTML before

HTML after

+++ b/core/core.libraries.yml
@@ -275,6 +275,7 @@ drupal.tabledrag:
+    - core/classList

+++ b/core/misc/tabledrag.es6.js
@@ -36,22 +36,27 @@
+              table.classList.add('tabledrag--processed');

This lib should be deprecated so I removed it see #2951857: Update classList.js to 1.2.20180112

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.

voleger’s picture

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

Deprecation message requires updates.
... in drupal:9.1.0 and is removed from drupal:10.0.0.

hash6’s picture

Assigned: Unassigned » hash6

The patch #29, #28, and #32 does not work for 8.8.x. will need to create a new patch from scratch for 9.x.

hash6’s picture

Assigned: hash6 » Unassigned
voleger’s picture

Status: Needs work » Needs review
StatusFileSize
new18.34 KB

Rerolled against 9.1.0. Updated deprecation messages. Added legacy test class.

Status: Needs review » Needs work

The last submitted patch, 37: 3035343-37.patch, failed testing. View results

naresh_bavaskar’s picture

Assigned: Unassigned » naresh_bavaskar
naresh_bavaskar’s picture

Assigned: naresh_bavaskar » Unassigned
Status: Needs work » Needs review
StatusFileSize
new18.6 KB
new1.85 KB

About TestCases: 1 out of 3 fixed. Please review, I am not that much familiar with PHPUnit :)
Thanks!

Status: Needs review » Needs work

The last submitted patch, 40: 3035343-40.patch, failed testing. View results

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new1009 bytes
new18.31 KB

Re-roll and proper fix against patch from #37

+++ b/core/tests/Drupal/KernelTests/Core/Render/RendererLegacyTest.php
@@ -6,20 +6,12 @@
-   * Tests deprecation of the drupal_attach_tabledrag() function.
...
-   * @expectedDeprecation drupal_attach_tabledrag() is deprecated in

This changes destructive - that's exactly required deprecation testing!

nod_’s picture

Status: Needs review » Needs work
Issue tags: +JavaScript
  1. +++ b/core/lib/Drupal/Core/Render/Element/Table.php
    @@ -385,13 +392,168 @@ public static function preRenderTable($element) {
    +      $element['#attributes']['data-drupal-tabledrag-id'] = $element['#attributes']['id'];
    

    I would call that data-drupal-tabledrag, because that's not an ID anymore.

  2. +++ b/core/misc/tabledrag.es6.js
    @@ -36,22 +36,27 @@
    +        Array.prototype.forEach.call(
    +          context.querySelectorAll(
    +            '.tabledrag-enabled:not(.tabledrag--processed)',
    +          ),
    +          table => {
    +            if (base === table.getAttribute('data-drupal-tabledrag-id')) {
    +              table.classList.add('tabledrag--processed');
    +              initTableDrag(table, base);
    +            }
    +          },
    

    This is unnecessary. we haven't been using classes to check if the behavior has run since drupal 6 :)

    The only thing to do here is update the selector:

    .find(`[data-drupal-tabledrag="${base}"]`)
    

    And that should be all the necessary changes to the JS.

We could even do it like the js #states and put the whole configuration in the data attribute instead of relying on drupalSettings, that might simplify some things and prevent issues with conflicting names. ( edit ) or not, tabledrag is a complicated beast.

voleger’s picture

StatusFileSize
new506 bytes
new18.35 KB

#43 still needs to be addressed. Tried to fix the rest of the test fails.

andypost’s picture

At least new once() usage should not be added

voleger’s picture

So that's mean we have to revert last change in the #44 and introduce refactoring of Drupal.tableDrag.prototype.displayColumns, Drupal.tableDrag.prototype.hideColumns and Drupal.tableDrag.prototype.showColumns to get rid of usage .findOnce method.
Also, #43 still needs to be addressed.

nod_’s picture

At least new once() usage should not be added

We should definitely use .once when it's necessary, so please add it here. The dependency on jquery is a separate issue. When we get to a once version that does not rely on jquery I want to be able to script the update, which means that every piece of code should be using .once and it should be using it the same way everywhere.

andypost’s picture

Backward compatibility is what we getting broken if change js here, the issue is about deprecate function but it also need to improve data class.
How to creep scope here?

nod_’s picture

Status: Needs work » Needs review
StatusFileSize
new16.44 KB
new2.52 KB

I don't understand what's going on here. See the attached patch.

This is all the JS changes required to make this work. There is no BC break since the HTML still prints the ID that was used before. On the JS level we're still using .once like we always have so the rest of the scripts that extends the tabledrag and rely on .findOnce or .removeOnce will work as expected.

And on top of that I would remove the "-id" part of the new attribute name because that's not an ID. That part is not in the patch because I don't really care about the naming of the attribute either way.

That's it!

andypost’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs issue summary update, -Needs change record updates

Updated IS and CR mentioning attribute change which is used only by tabledrag.js internally

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Render/Element/Table.php
@@ -385,13 +392,168 @@ public static function preRenderTable($element) {
+    $tabledrag_id = self::$tableDragId++;

This is a subtle change - previously table drag IDs are starting from 0 and now they are stating from 1. I don't think we should can this behaviour in this refactor. We can default the static value to NULL and do the same logic as we had in drupal_attach_tabledrag() ... ie.

+++ b/core/includes/common.inc
@@ -337,35 +338,15 @@ function drupal_js_defaults($data = NULL) {
-  $tabledrag_id = (!isset($tabledrag_id)) ? 0 : $tabledrag_id + 1;
andypost’s picture

Status: Needs work » Reviewed & tested by the community

@alexpott it starts from 0 as it was, $tabledrag_id = self::$tableDragId++; https://3v4l.org/svJQV

EDIT if you need to start it from 1 then code will be $tabledrag_id = ++self::$tableDragId;

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  /**
   * Drag and drop table rows with field manipulation.
   *
   * Using the drupal_attach_tabledrag() function, any table with weights or
   * parent relationships may be made into draggable tables. Columns containing
   * a field may optionally be hidden, providing a better user experience.
   *
   * Created tableDrag instances may be modified with custom behaviors by
   * overriding the .onDrag, .onDrop, .row.onSwap, and .row.onIndent methods.
   * See blocks.js for an example of adding additional functionality to
   * tableDrag.
   *
   * @type {Drupal~behavior}
   */
  Drupal.behaviors.tableDrag = {

Need to fix the above mention in tabledrag.es6.js

+++ b/core/lib/Drupal/Core/Render/Element/Table.php
@@ -385,13 +392,168 @@ public static function preRenderTable($element) {
+  /**
+   * Assists in attaching the tableDrag JavaScript behavior to a themed table.
+   *
+   * Draggable tables should be used wherever an outline or list of sortable
+   * items needs to be arranged by an end-user. Draggable tables are very
+   * flexible and can manipulate the value of form elements placed within
+   * individual columns.
+   *
+   * To set up a table to use drag and drop in place of weight select-lists or
+   * in place of a form that contains parent relationships, the form must be
+   * themed into a table. The table must have an ID attribute set and it
+   * maybe set as follows:
+   * @code
+   * $table = [
+   *   '#type' => 'table',
+   *   '#header' => $header,
+   *   '#rows' => $rows,
+   *   '#attributes' => [
+   *     'id' => 'my-module-table',
+   *   ],
+   * ];
+   * return \Drupal::service('renderer')->render($table);
+   * @endcode
+   *
+   * In the theme function for the form, a special class must be added to each
+   * form element within the same column, "grouping" them together.
+   *
+   * In a situation where a single weight column is being sorted in the table,
+   * the classes could be added like this (in the theme function):
+   * @code
+   * $form['my_elements'][$delta]['weight']['#attributes']['class'] = ['my-elements-weight'];
+   * @endcode
+   *
+   * Each row of the table must also have a class of "draggable" in order to
+   * enable the drag handles:
+   * @code
+   * $row = [...];
+   * $rows[] = [
+   *   'data' => $row,
+   *   'class' => ['draggable'],
+   * ];
+   * @endcode
+   *
+   * When tree relationships are present, the two additional classes
+   * 'tabledrag-leaf' and 'tabledrag-root' can be used to refine the behavior:
+   * - Rows with the 'tabledrag-leaf' class cannot have child rows.
+   * - Rows with the 'tabledrag-root' class cannot be nested under a parent row.
+   *
+   * Calling Table::attachTabledrag() would then be written as such:
+   * @code
+   * Table::attachTabledrag('my-module-table', [
+   *   'action' => 'order',
+   *   'relationship' => 'sibling',
+   *   'group' => 'my-elements-weight',
+   * ];
+   * @endcode
+   *
+   * In a more complex case where there are several groups in one column (such
+   * as the block regions on the admin/structure/block page), a separate
+   * subgroup class must also be added to differentiate the groups.
+   * @code
+   * $form['my_elements'][$region][$delta]['weight']['#attributes']['class'] = ['my-elements-weight', 'my-elements-weight-' . $region];
+   * @endcode
+   *
+   * The 'group' option is still 'my-element-weight', and the additional
+   * 'subgroup' option will be passed in as 'my-elements-weight-' . $region.
+   * This also means that you'll need to call Table::attachTabledrag() once for
+   * every region added.
+   *
+   * @code
+   * foreach ($regions as $region) {
+   *   Table::attachTabledrag('my-module-table', [
+   *     'action' => 'order',
+   *     'relationship' => 'sibling',
+   *     'group' => 'my-elements-weight',
+   *     'subgroup' => 'my-elements-weight-' . $region,
+   *   ]);
+   * }
+   * @endcode
+   *
+   * In a situation where tree relationships are present, adding multiple
+   * subgroups is not necessary, because the table will contain indentations
+   * that provide enough information about the sibling and parent relationships.
+   * See MenuForm::BuildOverviewForm for an example creating a table containing
+   * parent relationships.
+   *
+   * @param array $element
+   *   A form element to attach the tableDrag behavior to.
+   * @param array $options
+   *   These options are used to generate JavaScript settings necessary to
+   *   configure the tableDrag behavior appropriately for this particular table.
+   *   An associative array containing the following keys:
+   *   - 'table_id': String containing the target table's id attribute. If the
+   *     table does not have an id, one will need to be set, such as
+   *     <table id="my-module-table">.
+   *   - 'action': String describing the action to be done on the form item.
+   *      Either 'match' 'depth', or 'order':
+   *     - 'match' is typically used for parent relationships.
+   *     - 'order' is typically used to set weights on other form elements with
+   *       the same group.
+   *     - 'depth' updates the target element with the current indentation.
+   *   - 'relationship': String describing where the "action" option should be
+   *     performed. Either 'parent', 'sibling', 'group', or 'self':
+   *     - 'parent' will only look for fields up the tree.
+   *     - 'sibling' will look for fields in the same group in rows above and
+   *       below it.
+   *     - 'self' affects the dragged row itself.
+   *     - 'group' affects the dragged row, plus any children below it (the
+   *       entire dragged group).
+   *   - 'group': A class name applied on all related form elements for this
+   *     action.
+   *   - 'subgroup': (optional) If the group has several subgroups within it,
+   *     this string should contain the class name identifying fields in the
+   *     same subgroup.
+   *   - 'source': (optional) If the $action is 'match', this string should
+   *     contain the classname identifying what field will be used as the source
+   *     value when matching the value in $subgroup.
+   *   - 'hidden': (optional) The column containing the field elements may be
+   *     entirely hidden from view dynamically when the JavaScript is loaded.
+   *     Set to FALSE if the column should not be hidden.
+   *   - 'limit': (optional) Limit the maximum amount of parenting in this
+   *     table.
+   *
+   * @see \Drupal\menu_ui\MenuForm::buildOverviewForm()
+   */
+  public static function attachTabledrag(&$element, array $options) {

Maintaining this massive docblock in two places is wrong. Also the old docblock still references the old function. I think the old docblock should be:

/**
 * Assists in attaching the tableDrag JavaScript behavior to a themed table.
 *
 * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
 *   \Drupal\Core\Render\Element\Table::attachTabledrag() instead.
 *
 * @see https://www.drupal.org/node/3035565
 * @see MenuForm::BuildOverviewForm()
 * @see \Drupal\Core\Render\Element\Table::attachTabledrag()
 */
alexpott’s picture

And on top of that I would remove the "-id" part of the new attribute name because that's not an ID. That part is not in the patch because I don't really care about the naming of the attribute either way.

This is a good point. It's a counter

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

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

andypost’s picture

+++ b/core/includes/common.inc
@@ -337,35 +338,15 @@ function drupal_js_defaults($data = NULL) {
+ * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
...
+  @trigger_error('drupal_attach_tabledrag() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Render\Element\Table::attachTabledrag() instead. See https://www.drupal.org/node/3035565', E_USER_DEPRECATED);

+++ b/core/tests/Drupal/KernelTests/Core/Render/RendererLegacyTest.php
@@ -0,0 +1,34 @@
+   * @expectedDeprecation drupal_attach_tabledrag() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Render\Element\Table::attachTabledrag() instead. See https://www.drupal.org/node/3035565

needs update to 9.2.0

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

claudiu.cristea’s picture

Issue summary: View changes
Status: Needs work » Needs review
  • Addressed remarks from #49, #53, #54, #56.
  • Updated the Drupal version to 9.3.0, including the change notice.
  • Added strict typing to the new method.
  • Updated the IS.
daffie’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The patch looks good.

The only thing that is missing to me is this (the code is coming from #3036010: Fold drupal_get_updaters() into Updater class, deprecate drupal_get_updaters()):

function drupal_static_reset($name = NULL) {
  switch ($name) {
    case 'drupal_get_updaters':
      @trigger_error("Using drupal_static_reset() with 'drupal_get_updaters' as parameter is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Updater\Updater::resetRegistryCache() instead. See https://www.drupal.org/node/3047258", E_USER_DEPRECATED);
      Updater::resetRegistryCache();
      return;
  }

If you disagree, then please explain why it is not nessecary.

The MR needs to be rerolled.

berdir’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll

Well, there is no such case because there is no replacement. There's no use case to reset this, it's not a cache, it's a counter. No contrib usage: drupal_static_reset('drupal_attach_tabledrag. So I think that's fine.

As far as I see the merge request can be merged fine with --squash, so I'd assume that we're still good here, it was updated very recently.

This is quite a big chunk of what's left in common.inc (the documentation, mostly), so lets do this :)

Note sure why the JS changes need to be in here, but @catch actually suggested that back in #25.

claudiu.cristea’s picture

catch’s picture

Status: Reviewed & tested by the community » Needs work

Just re-read #25 after seeing #61.

So the reason to ask for a change to data- instead of #id.

With dynamic page cache, there's no guarantee of uniqueness when using a static counter - if you have tabledrag in two blocks, they can end up with the same $tableDragId because they've been rendered in two different requests. This means you end up with duplicate HTML IDs which is invalid HTML, and also the attempt to keep them unique fails too - presumably this would mean a collision in Drupal.settings.

The patch fixes the duplicate HTML ID problem, but it's not addressing the overall issue of using a counter to build a page out of elements that might be built across multiple different requests and collide. To do that we'd need to use a random string instead of a counter, or encode the options in data attributes instead of using Drupal settings at all. This is the approach being taken in #1090592: [meta] Use HTML5 data-drupal-* attributes instead of #ID selectors in Drupal.settings.

The reason to mention it here, was that if we didn't use the counter, we wouldn't need to add the static protected property to the Table element. However while the MR switches to a data element, it's not removing the counter, and still adding the static property. This means we're not gaining very much from the change...

I think there are two options:

1. Remove the js changes and go back to using an #ID.

2. Use a random string instead of a counter so we get the benefit of not adding the new static property.

And then in a follow-up, we could look at encoding all of the information in a data attribute(s) and stop using Drupal settings in general, which ought to remove the need for either a counter or random string.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

voleger’s picture

Rebased 3035343-tabledrag branch in 3035343-tabledrag-9.4.x against 9.4.x branch
Based on 3035343-tabledrag-9.4.x branch I did separate 3035343-tabledrag-9.4.x-without-drupal_settings branch to address removal reference on table ID attribute. So basically I changed the location of configuration storage and put it in data attribute. Let's see how the tests going.

andypost’s picture

queued testing for new MR, not clear why there 3 of them

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

andypost’s picture

@voleger please rebase MR against 9.5 or 10.0

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kim.pepper’s picture

Status: Needs work » Needs review
Issue tags: -JavaScript +JavaScript
StatusFileSize
new20.34 KB

Came across this issue from #3015538: [META] Deprecate contents of common.inc and looks like it needed a rebase on 10.1.x. However, rather than opening another MR, I thought a patch would be quicker and easier.

Looks like tabledrag.js was renamed and had a bit of work done to it, so I've just kept it as is. Not sure whether this is correct or not.

Status: Needs review » Needs work

The last submitted patch, 72: 3035343-tabledrag-72.patch, failed testing. View results

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

voleger changed the visibility of the branch 3035343-tabledrag to hidden.

voleger’s picture

Status: Needs work » Needs review

Actualized MR !13249 and now needs review.

smustgrave’s picture

Status: Needs review » Needs work

Left some comments on the MR. Thanks!

voleger’s picture

Status: Needs work » Needs review

Addressed #80

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Do believe feedback has been addressed for this one.

voleger’s picture

voleger’s picture

Title: Deprecate drupal_attach_tabledrag(). Move its logic in Table form element » [PP-1] Deprecate drupal_attach_tabledrag(). Move its logic in Table form element
Status: Reviewed & tested by the community » Postponed

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

nicxvan’s picture

Title: [PP-1] Deprecate drupal_attach_tabledrag(). Move its logic in Table form element » Deprecate drupal_attach_tabledrag(). Move its logic in Table form element
Status: Postponed » Needs work

Taking this out of postponed since the referenced issue was reverted due to some deep complexities.

voleger’s picture

Status: Needs work » Needs review

Rerolled and addressed review comments

andypost’s picture

Status: Needs review » Reviewed & tested by the community

+1 to not wait other issue

nicxvan’s picture

Can we use a memory cache? https://www.drupal.org/node/3546856

catch’s picture

Status: Reviewed & tested by the community » Needs review

To use a memory cache I think we'd either need to attach an instance to a static property, or call in and out of a service from the element class via \Drupal.

We could consider doing the second option maybe?

Also is that logic something we could add test coverage for? Can't see it in the test changes in the MR.

smustgrave’s picture

Status: Needs review » Needs work

Since it's been 2 months moving to NW for #90/#89

daffie’s picture

Status: Needs work » Needs review

Rebased the PR and swithced to the use of memory cache.

nicxvan’s picture

Status: Needs review » Reviewed & tested by the community

I updated the deprecation message version.

I also updated the CR a bit.

I think the failures are random but I can't rerun them.

nicxvan’s picture

Thanks for rerunning those failures!

I actually didn't meant to RTBC before that happened.

Now that it is green, and we're using the memory cache I think this should be ready.

The way it's implemented is a bit novel but matches how the drupal static worked so I think it's fine.

I think this is ready for RTBC now.

  • catch committed f4c870ee on 11.x
    task: #3035343 Deprecate drupal_attach_tabledrag(). Move its logic in...

  • catch committed 770e6f08 on main
    task: #3035343 Deprecate drupal_attach_tabledrag(). Move its logic in...
catch’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

Nearly got confused because the main mr has 11.x at the end of the branch name, but it's just because this issue is old...

Committed/pushed to main and 11.x thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

quietone’s picture

Published the change record

Status: Fixed » Closed (fixed)

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