Skip to content
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

Prevent removing blocks if templateLock is set to insert #8201

Conversation

chrisvanpatten
Copy link
Member

Description

This PR restores the original behaviour of templateLock="insert", which disallows inserting and removing, but allows moving.

How has this been tested?

Tested with a custom block using <InnerBlocks />

Types of changes

Could be considered a breaking change because it changes the behaviour of this property, although it's restoring it to the original intention.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@chrisvanpatten
Copy link
Member Author

chrisvanpatten commented Jul 25, 2018

I still think there's a lot of merit in #8112, especially for more complex InnerBlocks situations (programmatic management of the block structure in particular, where you might want to disable insertion so you can handle it in a more custom way, for instance), but this is a good short term fix too.

// Prevents deletion if templateLock is "all" or "insert"
// (if a user can't insert blocks they shouldn't be able
// to remove them either)
return templateLock === 'all' || templateLock === 'insert';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: In other places we do !! templateLock (inserting blocks).

I think we should add a similar check to SharedBlockDeleteButton? what do you think? in case of a template containing a shared block.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, on both counts. But I didn't know a template could include a shared block — how does that work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Like, how do you know the name of the block slug to put into the template? Is it just the name you save, or a kebab-cased version of that?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try adding a shared block to a regular post and copy the result (it should be core/block with a ref attribute)

@chrisvanpatten
Copy link
Member Author

The logic got changed at some point that renders most of this PR moot, however the docs are still out of date. Going to open a new PR for that.

@chrisvanpatten chrisvanpatten deleted the fix/templatelock-insert-option branch August 10, 2018 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants