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

Cannot create reusable block if template lock is on #16008

Open
benplum opened this issue Jun 5, 2019 · 3 comments
Open

Cannot create reusable block if template lock is on #16008

benplum opened this issue Jun 5, 2019 · 3 comments

Comments

@benplum
Copy link

@benplum benplum commented Jun 5, 2019

Describe the bug
If a post uses a locked block template, the child blocks can not be converted into reusable blocks. If a reusable block is added via the code view the reusable block renders fine, as does selecting an existing reusable block from the inserter, but the option to convert an existing local block to a reusable block is not displayed.

To reproduce
Steps to reproduce the behavior:

  1. Add a locked block template to a post type.
  2. Add a new post of that type and insert a block (one that can theoretically be reused)
  3. Click on the block options and see that the option to convert to a reusable block is missing.

Expected behavior
The convert to reusable block should be an option for any block that is set to be reused.

@talldan
Copy link
Contributor

@talldan talldan commented Nov 14, 2019

Hi @benplum, thanks for creating the issue, and apologies it took a while for a response.

My feeling is that this behaviour is by design. Creating a reusable block replaces the current selection of blocks with the new reusable block. Looking at the docs for template locking (https://developer.wordpress.org/block-editor/developers/block-api/block-templates/#locking), the two options are:

all — prevents all operations. It is not possible to insert new blocks, move existing blocks, or delete blocks.
insert — prevents inserting or removing blocks, but allows moving existing blocks.

Both don't allow inserting or removing blocks, which is what would be involved in creating a reusable block.

I do think the docs could be updated to make this clearer though, so I've relabelled this issue as a documentation improvement.

@talldan talldan added [Type] Documentation Good First Issue and removed Needs Testing labels Nov 14, 2019
@pwkip
Copy link
Contributor

@pwkip pwkip commented May 4, 2020

While we could argue about allowing locked blocks to be reusable or not, I think the inner blocks (with templateLock={false}) should definitely be convertible to reusable blocks. This is not the case right now. Even if you define it explicitly on a block that is part of a template:

registerBlockType( 'my-plugin/content-part', {
  // ...
  supports: {
    reusable: true, // <--------- This has no effect on the block or any of its InnerBlocks
  },
  // ...
  edit( { className } ) {
    return (
      <div className={ className }>
        <InnerBlocks templateLock={ false } />
      </div>
    );
  },
}

Note that this is only the case if the block is loaded as part of a template AND template_lock='all' or 'insert'. With template_lock set to false, all blocks become reusable again.

This might be related to other problems with inner blocks inside a template-locked block: #11681

@talldan
Copy link
Contributor

@talldan talldan commented Jan 28, 2021

@pwkip Late reply, but that sounds like a different issue to the one reported here. Maybe make a new issue if there's not one already reported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants