Skip to content

Commit

Permalink
Fix Row block on legacy themes
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Sep 7, 2021
1 parent 4c32b46 commit 7c8c9cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
11 changes: 6 additions & 5 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ function () use ( $style ) {
*/
function gutenberg_restore_group_inner_container( $block_content, $block ) {
$group_with_inner_container_regex = '/(^\s*<div\b[^>]*wp-block-group(\s|")[^>]*>)(\s*<div\b[^>]*wp-block-group__inner-container(\s|")[^>]*>)((.|\S|\s)*)/';

if (
'core/group' !== $block['blockName'] ||
WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ||
1 === preg_match( $group_with_inner_container_regex, $block_content )
1 === preg_match( $group_with_inner_container_regex, $block_content ) ||
( isset( $block['attrs']['layout']['type'] ) && $block['attrs']['layout']['type'] !== 'default' )
) {
return $block_content;
}
Expand All @@ -171,7 +171,8 @@ function( $matches ) {
return $updated_content;
}

// This can be removed when plugin support requires WordPress 5.8.0+.
if ( ! function_exists( 'wp_restore_group_inner_container' ) ) {
add_filter( 'render_block', 'gutenberg_restore_group_inner_container', 10, 2 );
if ( function_exists( 'wp_restore_group_inner_container' ) ) {
remove_filter( 'render_block', 'wp_restore_group_inner_container', 10, 2 );
}
add_filter( 'render_block', 'gutenberg_restore_group_inner_container', 10, 2 );

10 changes: 6 additions & 4 deletions packages/block-library/src/group/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@ function GroupEdit( { attributes, setAttributes, clientId } ) {
const defaultLayout = useSetting( 'layout' ) || {};
const { tagName: TagName = 'div', templateLock, layout = {} } = attributes;
const usedLayout = !! layout && layout.inherit ? defaultLayout : layout;
const { type = 'default' } = usedLayout;
const layoutSupportEnabled = themeSupportsLayout || type !== 'default';

const blockProps = useBlockProps();
const innerBlocksProps = useInnerBlocksProps(
themeSupportsLayout
layoutSupportEnabled
? blockProps
: { className: 'wp-block-group__inner-container' },
{
templateLock,
renderAppender: hasInnerBlocks
? undefined
: InnerBlocks.ButtonBlockAppender,
__experimentalLayout: themeSupportsLayout ? usedLayout : undefined,
__experimentalLayout: layoutSupportEnabled ? usedLayout : undefined,
}
);

Expand All @@ -63,10 +65,10 @@ function GroupEdit( { attributes, setAttributes, clientId } ) {
}
/>
</InspectorControls>
{ themeSupportsLayout && <TagName { ...innerBlocksProps } /> }
{ layoutSupportEnabled && <TagName { ...innerBlocksProps } /> }
{ /* Ideally this is not needed but it's there for backward compatibility reason
to keep this div for themes that might rely on its presence */ }
{ ! themeSupportsLayout && (
{ ! layoutSupportEnabled && (
<TagName { ...blockProps }>
<div { ...innerBlocksProps } />
</TagName>
Expand Down

0 comments on commit 7c8c9cc

Please sign in to comment.