Skip to content

Commit

Permalink
[Layout]: Fix align controls for hybrid themes (#47961)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras authored Feb 13, 2023
1 parent b019306 commit 4008678
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,25 @@ export default function useAvailableAlignments( controls = DEFAULT_CONTROLS ) {
if ( ! controls.includes( 'none' ) ) {
controls = [ 'none', ...controls ];
}
const { wideControlsEnabled = false, themeSupportsLayout } = useSelect(
( select ) => {
const { getSettings } = select( blockEditorStore );
const settings = getSettings();
return {
wideControlsEnabled: settings.alignWide,
themeSupportsLayout: settings.supportsLayout,
};
},
[]
);
const {
wideControlsEnabled = false,
themeSupportsLayout,
isBlockBasedTheme,
} = useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
const settings = getSettings();
return {
wideControlsEnabled: settings.alignWide,
themeSupportsLayout: settings.supportsLayout,
isBlockBasedTheme: settings.__unstableIsBlockBasedTheme,
};
}, [] );
const layout = useLayout();
const layoutType = getLayoutType( layout?.type );
const layoutAlignments = layoutType.getAlignments( layout );
const layoutAlignments = layoutType.getAlignments(
layout,
isBlockBasedTheme
);

if ( themeSupportsLayout ) {
const alignments = layoutAlignments.filter(
Expand Down
17 changes: 16 additions & 1 deletion packages/block-editor/src/layouts/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default {
getOrientation() {
return 'vertical';
},
getAlignments( layout ) {
getAlignments( layout, isBlockBasedTheme ) {
const alignmentInfo = getAlignmentsInfo( layout );
if ( layout.alignments !== undefined ) {
if ( ! layout.alignments.includes( 'none' ) ) {
Expand All @@ -74,6 +74,21 @@ export default {
{ name: 'right' },
];

// This is for backwards compatibility with hybrid themes.
if ( ! isBlockBasedTheme ) {
const { contentSize, wideSize } = layout;
if ( contentSize ) {
alignments.unshift( { name: 'full' } );
}

if ( wideSize ) {
alignments.unshift( {
name: 'wide',
info: alignmentInfo.wide,
} );
}
}

alignments.unshift( { name: 'none', info: alignmentInfo.none } );

return alignments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const BLOCK_EDITOR_SETTINGS = [
'__unstableHasCustomAppender',
'__unstableIsPreviewMode',
'__unstableResolvedAssets',
'__unstableIsBlockBasedTheme',
];

/**
Expand Down

1 comment on commit 4008678

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 4008678.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4161181167
📝 Reported issues:

Please sign in to comment.