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

Closed
benplum opened this issue Jun 5, 2019 · 4 comments
Closed

Cannot create reusable block if template lock is on #16008

benplum opened this issue Jun 5, 2019 · 4 comments
Labels
[Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) [Feature] Templates API Related to API powering block template functionality in the Site Editor Good First Issue An issue that's suitable for someone looking to contribute for the first time [Type] Developer Documentation Documentation for developers

Comments

@benplum
Copy link

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.

@swissspidy swissspidy added [Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) Needs Testing Needs further testing to be confirmed. [Feature] Templates API Related to API powering block template functionality in the Site Editor labels Jun 6, 2019
@talldan
Copy link
Contributor

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] Developer Documentation Documentation for developers Good First Issue An issue that's suitable for someone looking to contribute for the first time and removed Needs Testing Needs further testing to be confirmed. labels Nov 14, 2019
@pwkip
Copy link
Contributor

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 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.

@youknowriad
Copy link
Contributor

Going to close this issue in favor of #11681 as it's the same one really (just manifesting slightly differently).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) [Feature] Templates API Related to API powering block template functionality in the Site Editor Good First Issue An issue that's suitable for someone looking to contribute for the first time [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

No branches or pull requests

5 participants