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

Allowedblocks in locked template #18711

Closed
janeschindler opened this issue Nov 24, 2019 · 6 comments
Closed

Allowedblocks in locked template #18711

janeschindler opened this issue Nov 24, 2019 · 6 comments
Labels
[Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P [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

@janeschindler
Copy link

janeschindler commented Nov 24, 2019

Note from @talldan: This turned out not to be a bug, but the documentation needs an update, see
#18711 (comment)

Describe the bug
It used to be possible to create a container block with InnerBlocks, with allowedBlocks set there, and page template_lock set to all and the page template set to this container block – this meant that the whole post was locked except inside the container block, where only specific blocks were allowed. But in Wordpress 5.3 this no longer works for me. When I create this situation, I still can't add any blocks, including the explicitly allowed blocks, regardless of whether the block templateLock is set to true or false.

To reproduce

  1. make a post type with template_lock set to all and template including a new block type ("mycontainer").
  2. Set mycontainer to have allowedBlocks like "core/paragraph" and "core/image".

Expected behavior
The post type only allows blocks in the set order defined in the post type; it is not possible to move these blocks. But INSIDE the mycontainer block, the allowed blocks can be moved and added.

Additional context
Wordpress 5.3
The situation I expect is described here:
#12308
But it is no longer working.
My problem is described here:
#12288
But this person no longer has this problem, whereas I do....

@noahtallen
Copy link
Member

Does this bug describe your issue as well? #11681

@janeschindler
Copy link
Author

Thanks for the reply - No. I don’t have an issue refreshing. I simply can’t add any allowed blocks to my container block if template lock is on (and if it is off I can add blocks where I don’t want people to add them...)

@janeschindler
Copy link
Author

I noticed now that if I add templateLock={false} to my container block, it works as expected. I previously had tried with and without templateLock="false", which I assume caused some error (no blocks could be added; there was no error that I saw). But maybe it should work without any templateLock setting within the container block? And it would be great if errors could be logged.

@talldan
Copy link
Contributor

talldan commented Jan 24, 2020

Hi @janeschindler, thanks for getting in touch and apologies for the delay in any response. I had a look into it and the reason this is happening is that the templateLock is inherited from the parent template. So in this case because your post has templateLock of 'all', so does the block's templateLock.

This is mentioned in the README file for InnerBlocks (https://github.com/WordPress/gutenberg/tree/master/packages/block-editor/src/components/inner-blocks#templatelock), but that should also be explained in the main docs - https://developer.wordpress.org/block-editor/developers/block-api/block-templates/ given that has examples both for creating posts and blocks with templates.

As such, I'll keep this issue open and it can be about updating the docs. Potentially, error handling for invalid values could be added as well, as you suggest.

@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 [Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P [Feature] Templates API Related to API powering block template functionality in the Site Editor labels Jan 24, 2020
@janeschindler
Copy link
Author

Oh, thanks, I see the note in the readme. It would be great if this could be added to the docs. The locking example in the docs is a php example, and it's not clear to me what the relationship between the locking capabilities there and those directly in JS is. False isn't mentioned, but it might only be relevant for JS. It would be nice of the 'nested templates' section could also talk about how to lock/unlock and how allowed blocks works for nested blocks. And even nicer would be if the locking could be written into the PHP nested templates. Then developers could do a lot with existing blocks without always having to make more JS blocks that just define core innerBlocks and locking constraints, which is what I did. Anyway: The more clarification the better, though I can see that writing documentation is hard and takes a lot of work... thanks for doing it!

PypWalters added a commit to PypWalters/gutenberg that referenced this issue Dec 20, 2020
Adds clarity to the documentation concern mentioned here: WordPress#18711
@stokesman
Copy link
Contributor

I looks like this should be closed since #27834.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P [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

4 participants