Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When moving a block to a new region and placing the block in any place other than directly below the region name, the block's position doesn't save. Repositioning the block within it's current region does save the position.
Proposed resolution
Resolve bug in JS.
Remaining tasks
User interface changes
Unsure.
API changes
n/a
Data model changes
n/a
Beta phase evaluation
Issue category | Bugfix |
---|---|
Issue priority | Major because it's a bug |
Unfrozen changes | Unfrozen because it only changes CSS/markup/strings/documentation/tests. (Which? Specify.) |
Prioritized changes | Yes because it's a bug |
Disruption | N/A |
Comment | File | Size | Author |
---|---|---|---|
#26 | block_position_not-2544066-26.patch | 3.37 KB | joelpittet |
#26 | interdiff.txt | 881 bytes | joelpittet |
#19 | core-js-tabledrag-weights-2544066-19.patch | 3.07 KB | legolasbo |
#16 | interdiff.txt | 2.85 KB | nod_ |
#16 | core-js-tabledrag-weights-2544066-16.patch | 3.07 KB | nod_ |
Comments
Comment #1
legolasboI've managed to reproduce this issue and will start work on fixing it.
Comment #2
legolasboblock.js
contained an if statement that checked if the block was directly below a region label before updating the region/weight elements. I've removed this if statement and the issue is resolved. See attached patch.Comment #3
joelpittetThank you very much @legolasbo that seems to make it at least save to the other region(which is huge!) but there still seems to be a position order bug (may warrant a new issue?)
If you drag between regions where the target region has a block in it. Drag it to the top of that region and when you hit save, it is in that region but seems to go to the bottom.
New screencast:
Comment #4
legolasbo@joelpittet, thanks for the review. I will take a look at it on Thursday.
Comment #5
joelpittetThanks @legolasbo, I'll be around at a sprint in Chicago for MWDS then, so please ping me on IRC if you have any questions or need another review. Also side note, I'm considering opening up a new issue to replace that silly regex region name parsing with a data attribute to store the value instead of parsing it each time it's dropped.
Comment #6
legolasboAttached patch fixes the ordering problem. I have however noticed that the block is now no longer placed at the bottom if you manually select the region using the select box. This seems to be occur because using the select box triggers a drop event on the tabledrag element (HUH?? WTF??!!) for no apparent reason. It does however seem to place the block in the second to last position consequently.
Any ideas on how to find out wether or not the row was actually dropped or updated by the select box?
Comment #7
legolasboAttached patch fixes the following
tableDrag.onDrop
. (Also occurs in D7)Comment #8
legolasboComment #9
legolasboUpdated the patch to only adjust block weights in the (drop-)target region to minimise disruption in (features)config when changing block positioning.
Comment #10
legolasboIgnore #9. I forgot to rebase my local branch.
Comment #11
legolasboFixed eslint error.
Comment #12
nod_I'd like to keep the .eq() and avoid using .last() here.
Comment #13
Ankit Agrawal CreditAttribution: Ankit Agrawal as a volunteer commentedReplaced the .last() with .eq().
Comment #14
legolasboThanks Ankit Agrawal,
I tested your changes and everything is still working the way it should. However, since i did most of the work on this patch, someone else should review it thoroughly.
Comment #15
hussainwebNit: Comments should end with periods. It can be fixed on commit.
Comment #16
nod_Simplified some jQuery stuff, made the variable and method name follow our naming standards, added JSDoc for the new function (replace the duplicated inline comments from comment above).
Was RTBC for me so if legolasbo can test it to make sure my refactor didn't break stuff, feel free to RTBC afterwards.
Comment #17
legolasboI only reviewed the code, still have to do manual testing.
Weight should be incremented before being used as a value, not after. That way we'll always have an unused weight setting before and after the blocks, which makes manually setting the weights easier for users who prefer to do it that way.
Comment #18
joelpittetFrom manual testing it works great for all things! I'd RTBC it now if #17 can be sorted out between you too. Personally I'm not concerned about it if things are working, but there may be some gotchas if that is wrong in some way.
Comment #19
legolasboThe current behaviour never sets the weight to be the maximum/minimum allowed value. Which is something the patch in #16 changes. By incrementing first we keep that part of the original behaviour in tact.
I manually changed
return weight++;
toreturn ++weight;
in the patch, since I don't have developer tools on this machine.Other than that no changes.
Comment #20
legolasboComment #21
nod_Oh i see! Didn't get what it was for. Attention to detaiks++ :)
Would it be possible to do a +1 on the Math.round line with a comment explaining why it's there? This would be our first legitimate use of this form of ++. And i'd rather keep weight++ so that people don't have to wander about why it's like that.
But that's really minor.
Comment #22
legolasbo@nod_,
That would result in a "let's take the result of this Math.round operation, make it a negative number and increase it by 1". Seems really confusing and hard to document. I'd be more inclined to just document the ++weight and explain why we increment it first.
Comment #23
nod_That would pretty much be the same comment. It's just for consistency.
Comment #24
legolasbo@nod_,
If you think so I'm fine with either way. Unfortunately I'm currently not on a pc which is set up for development. Could you adjust the patch as you see fit? Then @joelpittet can RTBC it.
Comment #25
nod_On my phone too. Can't update
Comment #26
joelpittetThank you both, I've added your comment (reflowed to 80chars). This should not block me from RTBCing it because I didn't write the comment and I reviewed it and it all makes sense and both of you have approved it before hand.
Comment #27
webchickYikes, that's pretty bad. Nice find. /me pines for JS testing :\
Committed and pushed to 8.0.x. Thanks!
Moving back to D7 for backport.
Comment #35
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commentedI have tested this on D7 and it seems like that the issue is not present here. The code for D7 is a bit different and blocks are correctly saved when moved to another region (as illustrated in issue summary gif). So I am closing this.