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

Discuss api for disabling blocks after registration #1132

Closed
braders opened this issue Jun 11, 2017 · 12 comments
Closed

Discuss api for disabling blocks after registration #1132

braders opened this issue Jun 11, 2017 · 12 comments
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Blocks Overall functionality of blocks [Feature] Inserter The main way to insert blocks using the + button in the editing interface [Type] Task Issues or PRs that have been broken down into an individual action to take

Comments

@braders
Copy link

braders commented Jun 11, 2017

Quite a bit of discussion has taken place around how to register blocks, but I have not seen any mention of how these blocks could later be disabled (hidden, unregistereded). This might seem like a strange thing to want to do, but I think it could have a number of use cases:

  • Disable core blocks - a number of core blocks might not be appropriate for every theme, especially where the theme is bespoke or private. For example, a parallax block has been discussed which may not work with some front-end designs. For older themes, some blocks will never have been considered, and may require significant work to fit the theme; in these cases simply disabling the problem blocks seems a good compromise.

  • disable plugin blocks - plugins often try to do many things (often too much imho), and so you may wish to disable one or more blocks, whilst retaining the rest of the plugin's functionality.

  • based on post type - It may be desirable to have a block available only for certain post types. (Potentially​ useful for both themes & plugins)

  • based on dom &/or js events - for example enabling/ disabling blocks based on the page template value (or other fields and post meta).

@westonruter
Copy link
Member

Yeah, certain blocks should also potentially need to be disabled for page templates, when those get implemented. A template could, for example, have a fixed set of block slots that only accept given block types. So non-supported block types should be blocked in that case.

@mtias
Copy link
Member

mtias commented Jun 11, 2017

@aduth
Copy link
Member

aduth commented Jun 12, 2017

I don't know that an issue was ever created for it, but there was some previous discussion about the reverse for the same intent. In other words, it's not that you'd disable blocks, but rather no blocks are enabled by default and all blocks must be opted-in as relevant for the editor session.

Another cited example being blocks relevant to page building once we reach that point.

@BE-Webdesign
Copy link
Contributor

Somewhat related, would be to create individual registries: #336

This idea could have many usecases, like registering core blocks, registering woocommerce blocks, and combining different sets to make the total available blocks for a particular instance of the editor.

@mrjarbenne
Copy link

As a K12 Educational institution, we would need to disable blocks like College Humor, and Funny or Die, just to avoid advertising that you can embed content from those sites on our network. Existence infers endorsement in these cases, and we would want parents thinking we had populated the Embed menu with a vetted list of sites.

@jasmussen jasmussen added [Feature] Block API API that allows to express the block paradigm. [Feature] Blocks Overall functionality of blocks [Type] Question Questions about the design or development of the editor. [Feature] Inserter The main way to insert blocks using the + button in the editing interface labels Jun 22, 2017
@nylen
Copy link
Member

nylen commented Jun 22, 2017

It seems like all of this should be doable with our existing API functions. I expect you can unregister or otherwise manipulate blocks in the same place that you can register other ones, and the main thing to work out here is code loading order of plugins that interact with the editor.

Then we want to test this feature by writing a simple plugin that unregisters specific blocks, possibly depending on custom code like post type.

@nylen nylen added [Type] Task Issues or PRs that have been broken down into an individual action to take and removed [Type] Question Questions about the design or development of the editor. labels Jun 22, 2017
@kopepasah
Copy link
Member

@nylen would you recommend creating a ticket on Gutenberg repo that someone may pickup to create an external plugin for testing? If the functionality for disabling blocks already exists, it seems like this issue can be closed.

@mtias
Copy link
Member

mtias commented Jun 29, 2017

Another issue we should open is a way to opt-in into specific blocks. Say for my post type I only want to allow "Image" and "Gallery" block", but I don't want to unregister every single block (and potentially every plugin added block).

@nylen
Copy link
Member

nylen commented Jun 29, 2017

@nylen would you recommend creating a ticket on Gutenberg repo that someone may pickup to create an external plugin for testing?

Yes, which depends on the method of injecting scripts and styles for other blocks (TBD, see #1420 for example). This testing will be really valuable, but at the moment there is a lot that we haven't figured out yet.

Say for my post type I only want to allow "Image" and "Gallery" block", but I don't want to unregister every single block

This is already possible with our existing APIs (loop over all blocks and unregister the ones you don't want). I don't think we should make it any easier than that.

@nylen nylen closed this as completed Jun 29, 2017
@mtias
Copy link
Member

mtias commented Jun 29, 2017

This is already possible with our existing APIs (loop over all blocks and unregister the ones you don't want).

Not if I don't know which ones may exist that I don't want. Think of providing an array of supported blocks instead of unregistering the ones you don't want.

@nylen
Copy link
Member

nylen commented Jun 29, 2017

Yes, this is fine. The logic would look something like this:

getBlocks().forEach( block => {
    switch ( block.name ) {
        case 'core/text':
        case 'core/image':
            // Leave it alone
            break;
        default:
            unregisterBlock( block.name );
            break;
    }
} );

This seems like such an edge case that we shouldn't support it any further than that. It would effectively break any plugins that add blocks, for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Blocks Overall functionality of blocks [Feature] Inserter The main way to insert blocks using the + button in the editing interface [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

No branches or pull requests

9 participants