Skip to content
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

Fix merge algorithm for global styles #24294

Merged
merged 2 commits into from
Jul 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,20 @@ function gutenberg_experimental_global_styles_merge_trees( $core, $theme, $user
$result = gutenberg_experimental_global_styles_normalize_schema( array() );

foreach ( array_keys( $core ) as $block_name ) {
foreach ( array( 'presets', 'styles', 'features' ) as $subtree ) {
foreach ( array( 'presets', 'features' ) as $subtree ) {
$result[ $block_name ][ $subtree ] = array_merge(
$core[ $block_name ][ $subtree ],
$theme[ $block_name ][ $subtree ],
$user[ $block_name ][ $subtree ]
);
}
foreach ( array_keys( $core[ $block_name ]['styles'] ) as $subtree ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we expect the "core" styles to always contain all the keys?

Copy link
Member Author

Choose a reason for hiding this comment

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

With the current implementation, yes, as they all are normalized before being merged.

$result[ $block_name ]['styles'][ $subtree ] = array_merge(
$core[ $block_name ]['styles'][ $subtree ],
$theme[ $block_name ]['styles'][ $subtree ],
$user[ $block_name ]['styles'][ $subtree ]
);
}
}

return $result;
Expand All @@ -516,7 +523,10 @@ function gutenberg_experimental_global_styles_merge_trees( $core, $theme, $user
*/
function gutenberg_experimental_global_styles_normalize_schema( $tree ) {
$block_schema = array(
'styles' => array(),
'styles' => array(
'typography' => array(),
'color' => array(),
),
'features' => array(),
'presets' => array(),
);
Expand Down