Closed (fixed)
Project:
Drupal core
Version:
11.x-dev
Component:
forms system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
24 Feb 2019 at 11:44 UTC
Updated:
3 Oct 2026 at 11:45 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
claudiu.cristeaComment #3
claudiu.cristeaComment #4
andypostInitial patch, it needs to get rid of
drupal_static()inside, fix docs usage and file CRComment #5
andypostAdded cr, fixed docs, added test
Comment #7
claudiu.cristeaWhat 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 usestatic::?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...
Comment #8
andypost@claudiu.cristea I think the same way about static vs self but self works the same way here https://3v4l.org/6p6kv
Comment #9
mcannon commentedThe 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.
Comment #10
claudiu.cristeaWell, 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
Comment #11
andypost@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
Comment #12
andypostAdded contrib usage (not huge) to summary http://grep.xnddx.ru/search?text=drupal_attach_tabledrag
Comment #13
claudiu.cristea@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: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:Comment #14
claudiu.cristeaNits:
One has a non-namespaced class name, the other is only the method name. Let's write both with the full-qualified class namespace.
Words "may be" can go one line up.
Word "containing" should go one line up.
Words "If the" should go one line up. After that, aslo "such as".
Also "should be" goes 1 line up.
Comment #15
andypostAddressed all comments
Comment #16
andypostbtw checked phpdoc and found no strong suggestion about using FQDN for that but it looks really better
Comment #17
claudiu.cristeaNice!
Looks like this was left out.
Comment #18
andypostoh, yep
Comment #19
claudiu.cristeaGreat!
Comment #21
andypostQueued retest, looks
Drupal\Tests\media\FunctionalJavascript\MediaStandardProfileTesthas random failuresComment #23
andypostReroll after #3000057: Deprecate drupal_set_time_limit() and file_upload_max_size() and move to Environment component
Comment #24
andypostback to rtbc
Comment #25
catchPartly 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.
Comment #27
claudiu.cristea@catch, then we should rescope this issue. Needs IS and CR update.
Let's move to Drupal 8.8.0. Also the CR https://www.drupal.org/node/3035565 needs update.
Comment #28
andypostFix message
Comment #29
finnsky commentedUpdated patch js with data-drupal-tabledrag-id attribute as mentioned in #25
Comment #31
finnsky commentedseems tests should be updated aswell
Comment #32
andypostThe book ordering is broken because of weight processed wrong
Now it looks like
HTML before
HTML after
This lib should be deprecated so I removed it see #2951857: Update classList.js to 1.2.20180112
Comment #34
volegerDeprecation message requires updates.
... in drupal:9.1.0 and is removed from drupal:10.0.0.Comment #35
hash6 commentedThe patch #29, #28, and #32 does not work for 8.8.x. will need to create a new patch from scratch for 9.x.
Comment #36
hash6 commentedComment #37
volegerRerolled against 9.1.0. Updated deprecation messages. Added legacy test class.
Comment #39
naresh_bavaskarComment #40
naresh_bavaskarAbout TestCases: 1 out of 3 fixed. Please review, I am not that much familiar with PHPUnit :)
Thanks!
Comment #42
andypostRe-roll and proper fix against patch from #37
This changes destructive - that's exactly required deprecation testing!
Comment #43
nod_I would call that
data-drupal-tabledrag, because that's not an ID anymore.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:
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.
Comment #44
voleger#43 still needs to be addressed. Tried to fix the rest of the test fails.
Comment #45
andypostAt least new
once()usage should not be addedComment #46
volegerSo that's mean we have to revert last change in the #44 and introduce refactoring of
Drupal.tableDrag.prototype.displayColumns,Drupal.tableDrag.prototype.hideColumnsandDrupal.tableDrag.prototype.showColumnsto get rid of usage.findOncemethod.Also, #43 still needs to be addressed.
Comment #47
nod_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.
Comment #48
andypostBackward 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?
Comment #49
nod_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!
Comment #50
andypostUpdated IS and CR mentioning attribute change which is used only by
tabledrag.jsinternallyComment #51
alexpottThis 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.
Comment #52
andypost@alexpott it starts from 0 as it was,
$tabledrag_id = self::$tableDragId++;https://3v4l.org/svJQVEDIT if you need to start it from 1 then code will be
$tabledrag_id = ++self::$tableDragId;Comment #53
alexpottNeed to fix the above mention in tabledrag.es6.js
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:
Comment #54
alexpottThis is a good point. It's a counter
Comment #56
andypostneeds update to 9.2.0
Comment #59
claudiu.cristeaComment #60
daffie commentedThe 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()):
If you disagree, then please explain why it is not nessecary.
The MR needs to be rerolled.
Comment #61
berdirWell, 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.
Comment #62
claudiu.cristeaRerolled in https://www.drupal.org/project/drupal/issues/3035343#mr843-note33743
Comment #63
catchJust 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
$tableDragIdbecause 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.
Comment #66
volegerRebased 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.
Comment #68
andypostqueued testing for new MR, not clear why there 3 of them
Comment #70
andypost@voleger please rebase MR against 9.5 or 10.0
Comment #72
kim.pepperCame 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.
Comment #79
volegerActualized MR !13249 and now needs review.
Comment #80
smustgrave commentedLeft some comments on the MR. Thanks!
Comment #81
volegerAddressed #80
Comment #82
smustgrave commentedDo believe feedback has been addressed for this one.
Comment #83
volegerI think it will be easier to implement once #3525331: Reuse element plugins as object wrappers around render arrays gets in.
Comment #84
volegerComment #86
nicxvan commentedTaking this out of postponed since the referenced issue was reverted due to some deep complexities.
Comment #87
volegerRerolled and addressed review comments
Comment #88
andypost+1 to not wait other issue
Comment #89
nicxvan commentedCan we use a memory cache? https://www.drupal.org/node/3546856
Comment #90
catchTo 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.
Comment #91
smustgrave commentedSince it's been 2 months moving to NW for #90/#89
Comment #92
daffie commentedRebased the PR and swithced to the use of memory cache.
Comment #93
nicxvan commentedI updated the deprecation message version.
I also updated the CR a bit.
I think the failures are random but I can't rerun them.
Comment #94
nicxvan commentedThanks 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.
Comment #97
catchNearly 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!
Comment #99
quietone commentedPublished the change record