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

Reference: https://www.drupal.org/core/beta-changes
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
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

legolasbo’s picture

Title: Block position not saved when dragged to bottom of another region » Block position not saved when below the first block of another region
Assigned: Unassigned » legolasbo
Issue summary: View changes

I've managed to reproduce this issue and will start work on fixing it.

legolasbo’s picture

Assigned: legolasbo » Unassigned
Issue summary: View changes
Status: Active » Needs review
FileSize
1.3 KB

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

joelpittet’s picture

Issue summary: View changes
Status: Needs review » Needs work
FileSize
1.67 MB

Thank 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:

legolasbo’s picture

@joelpittet, thanks for the review. I will take a look at it on Thursday.

joelpittet’s picture

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

legolasbo’s picture

Status: Needs work » Needs review
FileSize
1.82 KB
957 bytes

Attached 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?

legolasbo’s picture

Attached patch fixes the following

  1. The original issue
  2. The incorrect trigger of tableDrag.onDrop . (Also occurs in D7)
  3. The block weights not being updated correctly when selecting a region using the select element. (Also occurs in D7)
legolasbo’s picture

Issue tags: +Needs manual testing
legolasbo’s picture

Updated the patch to only adjust block weights in the (drop-)target region to minimise disruption in (features)config when changing block positioning.

legolasbo’s picture

Ignore #9. I forgot to rebase my local branch.

legolasbo’s picture

Fixed eslint error.

nod_’s picture

Status: Needs review » Needs work

I'd like to keep the .eq() and avoid using .last() here.

Ankit Agrawal’s picture

Replaced the .last() with .eq().

legolasbo’s picture

Status: Needs work » Needs review

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

hussainweb’s picture

+++ b/core/modules/block/js/block.js
@@ -88,16 +88,18 @@
+        // Update the block weights

@@ -106,11 +108,12 @@
+          // Update the block weights

Nit: Comments should end with periods. It can be fixed on commit.

nod_’s picture

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.

legolasbo’s picture

Status: Needs review » Needs work

I only reviewed the code, still have to do manual testing.

+++ b/core/modules/block/js/block.js
@@ -112,23 +111,29 @@
+            return weight++;

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.

joelpittet’s picture

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

legolasbo’s picture

The 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++; to return ++weight; in the patch, since I don't have developer tools on this machine.

Other than that no changes.

legolasbo’s picture

Status: Needs work » Needs review
nod_’s picture

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.

legolasbo’s picture

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

// Increment the weight before assigning it to prevent using the absolute
// minimum available weight. This way we always have an unused upper
// and lower bound, which makes manually setting the weights easier for
// users who prefer to do it that way.
nod_’s picture

That would pretty much be the same comment. It's just for consistency.

legolasbo’s picture

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

nod_’s picture

On my phone too. Can't update

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs manual testing
FileSize
881 bytes
3.37 KB

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

webchick’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Yikes, 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.

  • webchick committed c234b83 on 8.0.x
    Issue #2544066 by legolasbo, joelpittet, nod_, Ankit Agrawal: Block...

Status: Patch (to be ported) » Needs work

The last submitted patch, 26: block_position_not-2544066-26.patch, failed testing.

  • webchick committed c234b83 on 8.1.x
    Issue #2544066 by legolasbo, joelpittet, nod_, Ankit Agrawal: Block...

  • webchick committed c234b83 on 8.3.x
    Issue #2544066 by legolasbo, joelpittet, nod_, Ankit Agrawal: Block...

  • webchick committed c234b83 on 8.3.x
    Issue #2544066 by legolasbo, joelpittet, nod_, Ankit Agrawal: Block...

  • webchick committed c234b83 on 8.4.x
    Issue #2544066 by legolasbo, joelpittet, nod_, Ankit Agrawal: Block...

  • webchick committed c234b83 on 8.4.x
    Issue #2544066 by legolasbo, joelpittet, nod_, Ankit Agrawal: Block...
poker10’s picture

Version: 7.x-dev » 8.0.x-dev
Status: Needs work » Fixed
Issue tags: -JavaScript, -Needs backport to D7 +JavaScript

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

Status: Fixed » Closed (fixed)

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