Skip to content

Commit

Permalink
Allow layout controls to be disabled per block from theme.json (#53378)
Browse files Browse the repository at this point in the history
* Allow layout controls to be disabled per block from theme.json

* Use allowEditing instead of root

* Update docs.
  • Loading branch information
tellthemachines authored Aug 9, 2023
1 parent fec05ee commit e57bf0d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Settings related to layout.
| --- | --- | --- |--- |
| contentSize | string | | |
| wideSize | string | | |
| allowEditing | boolean | true | |

---

Expand Down
6 changes: 4 additions & 2 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ class WP_Theme_JSON_Gutenberg {
* @since 6.2.0 Added `dimensions.minHeight`, 'shadow.presets', 'shadow.defaultPresets',
* `position.fixed` and `position.sticky`.
* @since 6.3.0 Removed `layout.definitions`. Added `typography.writingMode`.
* @since 6.4.0 Added `layout.allowEditing`.
* @var array
*/
const VALID_SETTINGS = array(
Expand Down Expand Up @@ -379,8 +380,9 @@ class WP_Theme_JSON_Gutenberg {
'minHeight' => null,
),
'layout' => array(
'contentSize' => null,
'wideSize' => null,
'contentSize' => null,
'wideSize' => null,
'allowEditing' => null,
),
'position' => array(
'fixed' => null,
Expand Down
8 changes: 7 additions & 1 deletion packages/block-editor/src/hooks/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { getLayoutType, getLayoutTypes } from '../layouts';
import { useBlockEditingMode } from '../components/block-editing-mode';
import { LAYOUT_DEFINITIONS } from '../layouts/definitions';
import { kebabCase } from '../utils/object';
import { useBlockSettings } from './utils';

const layoutBlockSupportKey = 'layout';

Expand Down Expand Up @@ -136,6 +137,11 @@ export function useLayoutStyles( blockAttributes = {}, blockName, selector ) {
}

function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
const settings = useBlockSettings( blockName );
const {
layout: { allowEditing: allowEditingSetting },
} = settings;

const { layout } = attributes;
const defaultThemeLayout = useSetting( 'layout' );
const { themeSupportsLayout } = useSelect( ( select ) => {
Expand All @@ -153,7 +159,7 @@ function LayoutPanel( { setAttributes, attributes, name: blockName } ) {
);
const {
allowSwitching,
allowEditing = true,
allowEditing = allowEditingSetting ?? true,
allowInheriting = true,
default: defaultBlockLayout,
} = layoutBlockSupport;
Expand Down
5 changes: 5 additions & 0 deletions schemas/json/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@
"wideSize": {
"description": "Sets the max-width of wide (`.alignwide`) content. Also used as the maximum viewport when calculating fluid font sizes",
"type": "string"
},
"allowEditing": {
"description": "Disable the layout UI controls.",
"type": "boolean",
"default": true
}
},
"additionalProperties": false
Expand Down

0 comments on commit e57bf0d

Please sign in to comment.