add allowedBlocks attribute

This commit is contained in:
Ray Elliott 2020-08-17 11:58:28 +01:00
parent d1244444ba
commit e54d899ef5
1 changed files with 6 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import {
ColorPicker, ColorPicker,
PanelBody, PanelBody,
ToolbarGroup, ToolbarGroup,
// use __experimentalToolbarItem as ToolbarItem does not seem to be present(?)
__experimentalToolbarItem as ToolbarItem, __experimentalToolbarItem as ToolbarItem,
} from '@wordpress/components'; } from '@wordpress/components';
import { __ } from '@wordpress/i18n'; import { __ } from '@wordpress/i18n';
@ -18,16 +19,19 @@ import { __ } from '@wordpress/i18n';
const NAMESPACE = 'namespace'; // TODO const NAMESPACE = 'namespace'; // TODO
const SLUG = 'slug'; // TODO const SLUG = 'slug'; // TODO
const BLOCK_TITLE = 'Block Title'; // TODO const BLOCK_TITLE = 'Block Title'; // TODO
const BLOCK_CATEGORIES = ['common', 'formatting', 'layout', 'widgets', 'embed'];
const BLOCK_CATEGORY = BLOCK_CATEGORIES[3];
const INNER_TEMPLATE = [ const INNER_TEMPLATE = [
['core/heading', { placeholder: 'Article Title', className: 'heading' }], ['core/heading', { placeholder: 'Article Title', className: 'heading' }],
['core/paragraph', { placeholder: 'Article Text', className: 'text' }], ['core/paragraph', { placeholder: 'Article Text', className: 'text' }],
]; ];
const ALLOWED_BLOCKS = ['core/image', 'core/paragraph'];
registerBlockType(`${NAMESPACE}/${SLUG}`, { registerBlockType(`${NAMESPACE}/${SLUG}`, {
title: __(BLOCK_TITLE, NAMESPACE), title: __(BLOCK_TITLE, NAMESPACE),
category: 'widgets', category: BLOCK_CATEGORY,
supports: { supports: {
// Removes support for an HTML mode. // Removes support for an HTML mode.
@ -87,6 +91,7 @@ registerBlockType(`${NAMESPACE}/${SLUG}`, {
<div> <div>
<InnerBlocks <InnerBlocks
template={INNER_TEMPLATE} template={INNER_TEMPLATE}
allowedBlocks={ALLOWED_BLOCKS}
templateLock="all" templateLock="all"
/> />
</div> </div>