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

Allow the specification of blocks allowed within columns #25183

Merged
merged 3 commits into from
Oct 1, 2020
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
3 changes: 3 additions & 0 deletions packages/block-library/src/column/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"type": "number",
"min": 0,
"max": 100
},
"allowedBlocks": {
"type": "array"
}
},
"supports": {
Expand Down
4 changes: 3 additions & 1 deletion packages/block-library/src/column/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { useSelect, useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';

function ColumnEdit( {
attributes: { verticalAlignment, width },
attributes: { verticalAlignment, width, allowedBlocks },
setAttributes,
clientId,
} ) {
Expand Down Expand Up @@ -92,6 +92,8 @@ function ColumnEdit( {
className: classes,
style: hasWidth ? { flexBasis: width + '%' } : undefined,
} }
//Specify the blocks allowed to be placed within this column
allowedBlocks={ allowedBlocks }
/>
</>
);
Expand Down
5 changes: 4 additions & 1 deletion packages/block-library/src/columns/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"attributes": {
"verticalAlignment": {
"type": "string"
}
},
"allowedChildBlocks": {
"type": "array"
}
},
"supports": {
"anchor": true,
Expand Down
10 changes: 8 additions & 2 deletions packages/block-library/src/columns/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function ColumnsEditContainer( {
updateColumns,
clientId,
} ) {
const { verticalAlignment } = attributes;
const { verticalAlignment, allowedChildBlocks } = attributes;

const { count } = useSelect(
( select ) => {
Expand Down Expand Up @@ -91,6 +91,8 @@ function ColumnsEditContainer( {
</InspectorControls>
<InnerBlocks
allowedBlocks={ ALLOWED_BLOCKS }
//Specify the blocks allowed to be placed within the possible created child columns within this block
allowedChildBlocks={ allowedChildBlocks }
orientation="horizontal"
__experimentalTagName={ Block.div }
__experimentalPassedProps={ {
Expand Down Expand Up @@ -137,6 +139,7 @@ const ColumnsEditContainerWrapper = withDispatch(
*/
updateColumns( previousColumns, newColumns ) {
const { clientId } = ownProps;
const { allowedChildBlocks } = ownProps.attributes;
const { replaceInnerBlocks } = dispatch( 'core/block-editor' );
const { getBlocks } = registry.select( 'core/block-editor' );

Expand All @@ -163,14 +166,17 @@ const ColumnsEditContainerWrapper = withDispatch(
...times( newColumns - previousColumns, () => {
return createBlock( 'core/column', {
width: newColumnWidth,
allowedBlocks: allowedChildBlocks,
} );
} ),
];
} else if ( isAddingColumn ) {
innerBlocks = [
...innerBlocks,
...times( newColumns - previousColumns, () => {
return createBlock( 'core/column' );
return createBlock( 'core/column', {
allowedBlocks: allowedChildBlocks,
} );
} ),
];
} else {
Expand Down