-
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
Proposal: Block copy function #49463
Conversation
Size Change: +23 B (0%) Total Size: 1.44 MB
ℹ️ View Unchanged
|
I saw #49464 first, and I left a #49464 (comment) that is very close to the API proposed here. The only difference is that I asked whether Regardless, I like the proposal to offer a way to modify the behavior when copying blocks. It's going to be a useful addition. |
A transform is an interesting idea! It feels somewhat ergonomic since you can think of it as a transform from a block to "the clipboard". Yes I imagine this should affect both duplicating a block and copying a block to the clipboard. Agree this is a useful proposal especially for extenders. My only hesitation is that if we go with something like #49457 then I'd prefer to have a |
The idea of |
What and why
Adds a
copy
function to the block API that lets blocks customise what happens when the block is duplicated.The motivation for this is to handle cases such as #29693 where a block wants to track a foreign key of some kind.
It's not implemented in this PR, but it also would let us move away from using
__internalWidgetId
which is how the widget editor tracks which widget entity should be updated when a block is modified. It's a hack that works because__internalWidgetId
does not appear in theblock.json
and so is filtered out when the block is duplicated. Using acopy
function like above would make this behaviour explicit. (Admittedly it's awkward though because a copy function needs to be declared on every block type.)How to test
View instructions
Paste this into DevTools:
You will then have a Product block that simulates the use case in #29693. Insert the block and notice that a product with ID 1 is created. Duplicate the block and notice that a product with ID 2 is created.