Skip to content

Restrict copy/paste of a block in the editor when supports.multiple = false and supports.removal = false #53471

@Michelleeby

Description

@Michelleeby

What problem does this address?

Hello folks 👋🏼 we have a custom block that should always be on the page, should not be moved, and should not be removed. To accomplish this, supports.removal = false and supports.multiple = false in block.json. As well, the block pattern that provides the custom block to all posts restricts removing and moving the block.

The problem is that you are still able to copy and paste the block. This leads to a strange user experience. Since multiple is false, a message is given to the user after they paste the block that only 1 of the block is supported. However, because removal isn’t supported, the user cannot delete the pasted block. Only Undo seems to work.

What is your proposed solution?

It could be helpful for this issue if the combination of supports.multiple = false and supports.removal = false meant Copy and Paste of the block is not supported in the editor.

Right now, with those settings, copy and paste is still enabled and available via menu, and this seems expected when viewing the source.

<CopyMenuItem
blocks={ blocks }
onCopy={ onCopy }
/>

{ canDuplicate && (
<MenuItem
onClick={ pipe(
onClose,
onDuplicate,
updateSelectionAfterDuplicate
) }
shortcut={ shortcuts.duplicate }
>
{ __( 'Duplicate' ) }
</MenuItem>
) }

Notice canDuplicate is only influencing the Duplicate button and the CopyMenuItem exists without condition. I thought maybe a conditional existed earlier, but I checked onCopy and that doesn’t seem to be the case either.

onCopy() {
const selectedBlockClientIds = blocks.map(
( { clientId } ) => clientId
);
if ( blocks.length === 1 ) {
flashBlock( selectedBlockClientIds[ 0 ] );
}
notifyCopy( 'copy', selectedBlockClientIds );
},

So that’s what brings me here today. I’m curious if it would be as simple as adding a check on the copy button that is influenced by the supports.multiple in block.json. Similar to how it seems to work for Duplicate support.

Anyways, thanks for your time and I look forward to working together on this issue 😁

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions