-
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
Fix: Block manager doesn't respect allowed_block_types hook #16586
Fix: Block manager doesn't respect allowed_block_types hook #16586
Conversation
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.
How feasible would it be to include end-to-end tests here?
return blockTypes.filter( ( { name } ) => { | ||
return includes( allowedBlockTypes || [], name ); | ||
} ); | ||
} ); |
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.
I would think we need some dependencies (a second argument) here, at least blockTypes
and probably allowedBlockTypes
(or settings
)?
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.
Updated 👍
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createContext } from '@wordpress/element'; |
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.
I guess this is more for convenience in making the settings available to the modal component? I thought whether we had this tracked in state, but I guess that's only in the editor
and block-editor
modules. We could do the same in this module as well, but it might be a bit overkill for the one setting we're interested in (I also feel it's already become difficult to manage in the two modules it is present).
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.
Yes, I used context as a convenience. Adding it to the edit-post store seemed overkill, and it seemed it would just bring more confusion, I guess we can reconsider later if we have other reasons to add it. While if we add now, I think we can not easily remove them because of o back-compatibility.
b1e3450
to
d41a022
Compare
d41a022
to
d06885d
Compare
Hi @aduth, your feedback was addressed and an end 2 end test was added. |
@@ -23,18 +25,32 @@ function BlockManagerCategory( { | |||
toggleVisible, | |||
toggleAllVisible, | |||
} ) { | |||
if ( ! blockTypes.length ) { | |||
const settings = useContext( EditPostSettings ); | |||
const { allowedBlockTypes } = settings; |
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.
These are all available in the editor store why not just use that store instead of adding a new context provider?
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.
Hi @youknowriad, when a user disables a block in the block manager the block is removed from the editor store allowed blocks. Using just the editor store, it is not possible to differentiate between a block disabled by the user and a block restricted on the server using a plugin. In this case, we need to distinguish both cases.
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.
It's minor but It feels like something that can be solved in the store somehow instead of adding a new context for sharing data while we already have a context for that (the store).
Description
Fix: #15598
Currently, the block manager shows blocks that are not allowed by the allowed_block_types filter.
This PR fixes this problem by removing hiding these blocks from the block manager. The user should not notice the existence of blocks not allowed by the allowed_block_types so not showing them in the block manager seems the best approach.
How has this been tested?
I tested these changes without applying any filter, and things worked exactly as before.
I added the following code to functions.php of the currently enabled theme:
I verified only blocks that are returned by whitelistBlocks are part of the block manager; all other blocks don't appear at all.