-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Impossible to drag & drop blocks if locking is insert #14521
Fix: Impossible to drag & drop blocks if locking is insert #14521
Conversation
fe5dc81
to
6d3e49b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This indeed renders the dropzone, but when dropping the block in another place it doesn't work - blocks stay in the same position.
I've also checked that changing the template_lock
to all
in the example CPT provided disabled the block mover.
Cherry picked this commit on top of #14924 but still didn't work. |
6d3e49b
to
d59b0bb
Compare
d59b0bb
to
98c1ebe
Compare
Hi @nosolosw, it seems my analysis was wrong. This PR is not dependent on #14924. The condition to make this move work was already part of the moveBlockToPosition function. The problem was that fromRootClientId was '' and toRootClientId was undefined so the condition fromRootClientId === toRootClientId did not matched. I updated the code to make things work as expected, and this PR should fix the problem on its own. |
OK, this is what I've found: testing with the example provided works as described. I also wanted to test how this behaves with inner blocks, so I've added with
with
I guess we can prepare a different PR for fixing the |
Hi @nosolosw, this seems like the expected behavior given how locking inheritance works. A block inherits the locking from the parent if locking was not explicitly set. So I think given the inheritance logic we don't have any issue in the template_lock=all.
That restriction happens and the move is not possible because there is a locking insert on root level. #14924 addresses another issue where the move is allowed if we don't have locking on the root level, but we have locking insert in a child block. This logic is complex, I hope I managed to summarize it, but If I missed something in my explanation feel free to comment and I will expand. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works as expected and the code is fine.
I can repro in master
the issues I've reported in #14521 (comment) so this PR doesn't change the current behavior. Thanks for the added explanation about the locking mechanism, Jorge. My expectations on how should it work were different, but any further decision on updating it is orthogonal to this PR.
Description
If the CPT locking is set to insert it should be possible to move the blocks. Currently, it is possible to move the blocks using the block move buttons but not possible using drag & drop.
This PR fixes the problem of being impossible to use drag & drop when locking equals insert.
How has this been tested?
I pasted the contents of this gist https://gist.github.com/jorgefilipecosta/b50b090932b22bff1abe193fd0f5d649 in the functions.php file of the theme enable on my test website. I verified I can move the blocks using drag & drop while on master that is not possible.