Skip to content

Commit

Permalink
Fix allowed_block_types regression (#14229)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Mar 5, 2019
1 parent 44c58b8 commit 357175f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/block-editor/src/store/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const PREFERENCES_DEFAULTS = {
* disableCustomFontSizes boolean Whether or not the custom font sizes are disabled
* imageSizes Array Available image sizes
* maxWidth number Max width to constraint resizing
* blockTypes boolean|Array Allowed block types
* allowedBlockTypes boolean|Array Allowed block types
* hasFixedToolbar boolean Whether or not the editor toolbar is fixed
* focusMode boolean Whether the focus mode is enabled or not
* styles Array Editor Styles
Expand Down
24 changes: 24 additions & 0 deletions packages/e2e-tests/plugins/allowed-blocks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Plugin Name: Gutenberg Test Allowed Blocks
* Plugin URI: https://github.com/WordPress/gutenberg
* Author: Gutenberg Team
*
* @package gutenberg-test-allowed-blocks
*/

/**
* Restrict the allowed blocks in the editor.
*
* @param Array $allowed_block_types An array of strings containing the previously allowed blocks.
* @param WP_Post $post The current post object.
* @return Array An array of strings containing the new allowed blocks after the filter is applied.
*/
function my_plugin_allowed_block_types( $allowed_block_types, $post ) {
if ( 'post' !== $post->post_type ) {
return $allowed_block_types;
}
return array( 'core/paragraph', 'core/image' );
}

add_filter( 'allowed_block_types', 'my_plugin_allowed_block_types', 10, 2 );
36 changes: 36 additions & 0 deletions packages/e2e-tests/specs/plugins/allowed-blocks.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* WordPress dependencies
*/
import {
activatePlugin,
createNewPost,
deactivatePlugin,
searchForBlock,
} from '@wordpress/e2e-test-utils';

describe( 'Allowed Blocks Filter', () => {
beforeAll( async () => {
await activatePlugin( 'gutenberg-test-allowed-blocks' );
} );

beforeEach( async () => {
await createNewPost();
} );

afterAll( async () => {
await deactivatePlugin( 'gutenberg-test-allowed-blocks' );
} );

it( 'should restrict the allowed blocks in the inserter', async () => {
// The paragraph block is available.
await searchForBlock( 'Paragraph' );
const paragraphBlock = await page.$( `button[aria-label="Paragraph"]` );
expect( paragraphBlock ).not.toBeNull();
await paragraphBlock.click();

// The gallery block is not available.
await searchForBlock( 'Gallery' );
const galleryBlock = await page.$( `button[aria-label="Gallery"]` );
expect( galleryBlock ).toBeNull();
} );
} );
2 changes: 1 addition & 1 deletion packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class EditorProvider extends Component {
'disableCustomFontSizes',
'imageSizes',
'maxWidth',
'blockTypes',
'allowedBlockTypes',
'hasFixedToolbar',
'focusMode',
'styles',
Expand Down

0 comments on commit 357175f

Please sign in to comment.