Editor: Backport foundation for Layout block support refactor (part 1).
Backports the following changes from the Gutenberg repository: * [WordPress/gutenberg/40875 gutenberg/40875] Layout: Use semantic classnames, centralize layout definitions, reduce duplication, and fix blockGap in theme.json * [WordPress/gutenberg/42544 gutenberg/42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg/42544 * [WordPress/gutenberg/42087 gutenberg/42087] Theme.json: Add block support feature level selectors for blocks gutenberg/42087 * [WordPress/gutenberg/43792 gutenberg/43792] Global Styles: Split root layout rules into a different function gutenberg/43792 * [WordPress/gutenberg/42544 gutenberg/42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg/42544 * [WordPress/gutenberg/42665 gutenberg/42665] Layout: Reduce specificity of fallback blockGap styles gutenberg/42665 * [WordPress/gutenberg/42085 gutenberg/42085] Core CSS support for root padding and alignfull blocks gutenberg/42085 Notes: * It doesn't entirely port over PR 40875 — the remaining PHP changes for that PR will be explored in a separate PR targeting `layout.php`. * [54159] was reverted in [54160] due to PHPUnit test failures for tests added by the commit. Later, tests passed when applied on top of `trunk`. There were various outages today of upstream `wp-env` dependencies, which likely were the root cause of the earlier failures. For historical tracking and to make sure, recommitting [54159] but instead on top of current `trunk`. See PR 3205 for more details. * Giving additional props for those who did a deep dive investigation into the failed tests. Follow-up to [54160], [54159]. Props andrewserong, aaronrobertshaw, isabel_brison, bernhard-reiter, hellofromTonya. See #56467. Built from https://develop.svn.wordpress.org/trunk@54162 git-svn-id: http://core.svn.wordpress.org/trunk@53721 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -232,6 +232,54 @@ class WP_Theme_JSON_Resolver {
|
||||
return $with_theme_supports;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the styles for blocks from the block.json file.
|
||||
*
|
||||
* @since 6.1.0
|
||||
*
|
||||
* @return WP_Theme_JSON
|
||||
*/
|
||||
public static function get_block_data() {
|
||||
$registry = WP_Block_Type_Registry::get_instance();
|
||||
$blocks = $registry->get_all_registered();
|
||||
$config = array( 'version' => 1 );
|
||||
foreach ( $blocks as $block_name => $block_type ) {
|
||||
if ( isset( $block_type->supports['__experimentalStyle'] ) ) {
|
||||
$config['styles']['blocks'][ $block_name ] = static::remove_json_comments( $block_type->supports['__experimentalStyle'] );
|
||||
}
|
||||
|
||||
if (
|
||||
isset( $block_type->supports['spacing']['blockGap']['__experimentalDefault'] ) &&
|
||||
null === _wp_array_get( $config, array( 'styles', 'blocks', $block_name, 'spacing', 'blockGap' ), null )
|
||||
) {
|
||||
// Ensure an empty placeholder value exists for the block, if it provides a default blockGap value.
|
||||
// The real blockGap value to be used will be determined when the styles are rendered for output.
|
||||
$config['styles']['blocks'][ $block_name ]['spacing']['blockGap'] = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Core here means it's the lower level part of the styles chain.
|
||||
// It can be a core or a third-party block.
|
||||
return new WP_Theme_JSON( $config, 'core' );
|
||||
}
|
||||
|
||||
/**
|
||||
* When given an array, this will remove any keys with the name `//`.
|
||||
*
|
||||
* @param array $array The array to filter.
|
||||
* @return array The filtered array.
|
||||
*/
|
||||
private static function remove_json_comments( $array ) {
|
||||
unset( $array['//'] );
|
||||
foreach ( $array as $k => $v ) {
|
||||
if ( is_array( $v ) ) {
|
||||
$array[ $k ] = static::remove_json_comments( $v );
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the custom post type that contains the user's origin config
|
||||
* for the active theme or a void array if none are found.
|
||||
@@ -370,6 +418,7 @@ class WP_Theme_JSON_Resolver {
|
||||
* @since 5.8.0
|
||||
* @since 5.9.0 Added user data, removed the `$settings` parameter,
|
||||
* added the `$origin` parameter.
|
||||
* @since 6.1.0 Added block data.
|
||||
*
|
||||
* @param string $origin Optional. To what level should we merge data.
|
||||
* Valid values are 'theme' or 'custom'. Default 'custom'.
|
||||
@@ -382,6 +431,7 @@ class WP_Theme_JSON_Resolver {
|
||||
|
||||
$result = new WP_Theme_JSON();
|
||||
$result->merge( static::get_core_data() );
|
||||
$result->merge( static::get_block_data() );
|
||||
$result->merge( static::get_theme_data() );
|
||||
|
||||
if ( 'custom' === $origin ) {
|
||||
|
||||
Reference in New Issue
Block a user