-
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
Allow block creators to disable block deletion via block support. #18118
Allow block creators to disable block deletion via block support. #18118
Conversation
The eventual UI of the block I'm creating is supposed to look like this: I saw #7199 in which there is a lengthy conversation about options for extending the block menu. Was there ever a followup or do we need to make one? |
Should be noted that this also relates loosely to #16678 and #8112. I’d love to see this addressed holistically, to cover the various use-cases around how various block “actions” are available and unavailable, whether via Inserter or in the context of an InnerBlocks area. Support is currently somewhat patchy and inconsistent, unfortunately. |
Yeah, that's a great point. I think the block template API is very limited at the moment and can work in unexpected ways (see #11681 as well!). As the stuff you linked to develops, different UI elements could be covered - for example the remove button doesn't exist if the block can't do the remove action. I think also beyond that, there is a use case for individual blocks dynamically modifying the actions available. For example, the main goal of this PR is to allow a developer to dynamically disable the remove block action for a single block if a condition is not met. The current code is pretty limited in that regard, so I'll have to rework some aspects of this. |
@@ -112,6 +113,7 @@ export function BlockSettingsMenu( { clientIds } ) { | |||
<MenuGroup> | |||
{ ! isLocked && ( | |||
<MenuItem | |||
disabled={ ! canRemove } |
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.
in php, we might use a filter:
$disabled = apply_filters( 'should_disable_block_remove_button', false, $block_name );
I wonder what the best approach for doing something like that would be here. I'm familiar-ish with slot fill, but not familiar with JS filters/actions in Gutenberg.
Do we need to implement a store for something like how we remove settings panels?
It seems what I "really" want here is to be able to apply something like a
I'm not sure that working on a new |
I'm following up on this over here: #11681 (comment) IMO we need to fix the underlying inflexibility of the block template API so that it's easy to add things like this to it :) |
No longer relevant. I still think this is worth visiting in the future, but will need to put more thought into it when I'm working on something that more closely relates to this :) |
Description
Allow block developers to disable the ability to delete a specific block via block supports.
Some issues with this approach:
How has this been tested?
To test this yourself, create a new block with
supports: { removal: false }
. Insert the block into the editor and make sure you cannot delete it with backspace or through the UI.Screenshots
Types of changes
New feature.
Checklist:
Resolves #16364