-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Layout: Move layout definitions out of theme.json #50621
Changes from 6 commits
7cff18d
f9cc51b
deb1fb7
9c6d658
d49bbb8
ae7dfef
fde9a8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,189 @@ | |
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Returns layout definitions, keyed by layout type. | ||
* | ||
* Provides a common definition of slugs, classnames, base styles, and spacing styles for each layout type. | ||
* When making changes or additions to layout definitions, the corresponding JavaScript definitions should | ||
* also be updated. | ||
* | ||
* @return array[] Layout definitions. | ||
*/ | ||
function gutenberg_get_layout_definitions() { | ||
$layout_definitions = array( | ||
'default' => array( | ||
'name' => 'default', | ||
'slug' => 'flow', | ||
'className' => 'is-layout-flow', | ||
'baseStyles' => array( | ||
array( | ||
'selector' => ' > .alignleft', | ||
'rules' => array( | ||
'float' => 'left', | ||
'margin-inline-start' => '0', | ||
'margin-inline-end' => '2em', | ||
), | ||
), | ||
array( | ||
'selector' => ' > .alignright', | ||
'rules' => array( | ||
'float' => 'right', | ||
'margin-inline-start' => '2em', | ||
'margin-inline-end' => '0', | ||
), | ||
), | ||
array( | ||
'selector' => ' > .aligncenter', | ||
'rules' => array( | ||
'margin-left' => 'auto !important', | ||
'margin-right' => 'auto !important', | ||
), | ||
), | ||
), | ||
'spacingStyles' => array( | ||
array( | ||
'selector' => ' > :first-child:first-child', | ||
'rules' => array( | ||
'margin-block-start' => '0', | ||
), | ||
), | ||
array( | ||
'selector' => ' > :last-child:last-child', | ||
'rules' => array( | ||
'margin-block-end' => '0', | ||
), | ||
), | ||
array( | ||
'selector' => ' > *', | ||
'rules' => array( | ||
'margin-block-start' => null, | ||
'margin-block-end' => '0', | ||
), | ||
), | ||
), | ||
), | ||
'constrained' => array( | ||
'name' => 'constrained', | ||
'slug' => 'constrained', | ||
'className' => 'is-layout-constrained', | ||
'baseStyles' => array( | ||
array( | ||
'selector' => ' > .alignleft', | ||
'rules' => array( | ||
'float' => 'left', | ||
'margin-inline-start' => '0', | ||
'margin-inline-end' => '2em', | ||
), | ||
), | ||
array( | ||
'selector' => ' > .alignright', | ||
'rules' => array( | ||
'float' => 'right', | ||
'margin-inline-start' => '2em', | ||
'margin-inline-end' => '0', | ||
), | ||
), | ||
array( | ||
'selector' => ' > .aligncenter', | ||
'rules' => array( | ||
'margin-left' => 'auto !important', | ||
'margin-right' => 'auto !important', | ||
), | ||
), | ||
array( | ||
'selector' => ' > :where(:not(.alignleft):not(.alignright):not(.alignfull))', | ||
'rules' => array( | ||
'max-width' => 'var(--wp--style--global--content-size)', | ||
'margin-left' => 'auto !important', | ||
'margin-right' => 'auto !important', | ||
), | ||
), | ||
array( | ||
'selector' => ' > .alignwide', | ||
'rules' => array( | ||
'max-width' => 'var(--wp--style--global--wide-size)', | ||
), | ||
), | ||
), | ||
'spacingStyles' => array( | ||
array( | ||
'selector' => ' > :first-child:first-child', | ||
'rules' => array( | ||
'margin-block-start' => '0', | ||
), | ||
), | ||
array( | ||
'selector' => ' > :last-child:last-child', | ||
'rules' => array( | ||
'margin-block-end' => '0', | ||
), | ||
), | ||
array( | ||
'selector' => ' > *', | ||
'rules' => array( | ||
'margin-block-start' => null, | ||
'margin-block-end' => '0', | ||
), | ||
), | ||
), | ||
), | ||
'flex' => array( | ||
'name' => 'flex', | ||
'slug' => 'flex', | ||
'className' => 'is-layout-flex', | ||
'displayMode' => 'flex', | ||
'baseStyles' => array( | ||
array( | ||
'selector' => '', | ||
'rules' => array( | ||
'flex-wrap' => 'wrap', | ||
'align-items' => 'center', | ||
), | ||
), | ||
array( | ||
'selector' => ' > *', | ||
'rules' => array( | ||
'margin' => '0', | ||
), | ||
), | ||
), | ||
'spacingStyles' => array( | ||
array( | ||
'selector' => '', | ||
'rules' => array( | ||
'gap' => null, | ||
), | ||
), | ||
), | ||
), | ||
'grid' => array( | ||
'name' => 'grid', | ||
'slug' => 'grid', | ||
'className' => 'is-layout-grid', | ||
'displayMode' => 'grid', | ||
'baseStyles' => array( | ||
array( | ||
'selector' => ' > *', | ||
'rules' => array( | ||
'margin' => '0', | ||
), | ||
), | ||
), | ||
'spacingStyles' => array( | ||
array( | ||
'selector' => '', | ||
'rules' => array( | ||
'gap' => null, | ||
), | ||
), | ||
), | ||
), | ||
); | ||
|
||
return $layout_definitions; | ||
} | ||
|
||
/** | ||
* Registers the layout block attribute for block types that support it. | ||
* | ||
|
@@ -409,7 +592,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { | |
} | ||
|
||
$class_names = array(); | ||
$layout_definitions = _wp_array_get( $global_layout_settings, array( 'definitions' ), array() ); | ||
$layout_definitions = gutenberg_get_layout_definitions(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A few lines above, there's some code to query for the data stored in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, good catch! Yes, there's no longer a need to check for We still need the overall |
||
$container_class = wp_unique_id( 'wp-container-' ); | ||
$layout_classname = ''; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1272,7 +1272,7 @@ protected function get_layout_styles( $block_metadata ) { | |
$has_block_gap_support = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'blockGap' ) ) !== null; | ||
$has_fallback_gap_support = ! $has_block_gap_support; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback gap styles support. | ||
$node = _wp_array_get( $this->theme_json, $block_metadata['path'], array() ); | ||
$layout_definitions = _wp_array_get( $this->theme_json, array( 'settings', 'layout', 'definitions' ), array() ); | ||
$layout_definitions = gutenberg_get_layout_definitions(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also need to remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happened if 3rd parties provided There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I've removed it from |
||
$layout_selector_pattern = '/^[a-zA-Z0-9\-\.\ *+>:\(\)]*$/'; // Allow alphanumeric classnames, spaces, wildcard, sibling, child combinator and pseudo class selectors. | ||
|
||
// Gap styles will only be output if the theme has block gap support, or supports a fallback gap. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nice to add the file path for the JS definitions here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of adding that in originally, but once we backport the changes, any JS path won't quite make sense from the perspective of
wordpress-develop
, so I thought I'd leave it off for now. Happy to add it in once we've done the backports, though!