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

Fix allowed_block_types regression #14229

Merged
merged 2 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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