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

Add initial support for themes to control the editor #24275

Merged
merged 3 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
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
49 changes: 0 additions & 49 deletions lib/editor-features.php

This file was deleted.

55 changes: 37 additions & 18 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,39 +536,54 @@ function gutenberg_experimental_global_styles_normalize_schema( $tree ) {
}

/**
* Returns the stylesheet resulting of merging
* core's, theme's, and user's origins.
* Takes data from the different origins (core, theme, and user)
* and returns the merged result.
*
* @return string
* @return array Merged trees.
*/
function gutenberg_experimental_global_styles_get_stylesheet() {
$gs_merged = array();
$gs_core = gutenberg_experimental_global_styles_get_core();
$gs_theme = gutenberg_experimental_global_styles_get_theme();
$gs_user = gutenberg_experimental_global_styles_get_user();
function gutenberg_experimental_global_styles_get_merged_origins() {
oandregal marked this conversation as resolved.
Show resolved Hide resolved
$core = gutenberg_experimental_global_styles_get_core();
$theme = gutenberg_experimental_global_styles_get_theme();
$user = gutenberg_experimental_global_styles_get_user();
$merged = gutenberg_experimental_global_styles_merge_trees( $core, $theme, $user );

$gs_merged = gutenberg_experimental_global_styles_merge_trees( $gs_core, $gs_theme, $gs_user );

$stylesheet = gutenberg_experimental_global_styles_resolver( $gs_merged );
if ( empty( $stylesheet ) ) {
return;
}
return $stylesheet;
return $merged;
}

/**
* Fetches the preferences for each origin (core, theme, user)
* and enqueues the resulting stylesheet.
*/
function gutenberg_experimental_global_styles_enqueue_assets() {

$stylesheet = gutenberg_experimental_global_styles_get_stylesheet();
$merged = gutenberg_experimental_global_styles_get_merged_origins();
$stylesheet = gutenberg_experimental_global_styles_resolver( $merged );
if ( empty( $stylesheet ) ) {
return;
}

wp_register_style( 'global-styles', false, array(), true, true );
wp_add_inline_style( 'global-styles', $stylesheet );
wp_enqueue_style( 'global-styles' );
}

/**
* Returns the default config for editor features,
* or an empty array if none found.
*
* @param array $config Config to extract values from.
* @return array Default features config for the editor.
*/
function gutenberg_experimental_global_styles_get_editor_features( $config ) {
if (
empty( $config['global']['features'] ) ||
! is_array( $config['global']['features'] )
) {
return array();
}

return $config['global']['features'];
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really think we should pass just the "global" features to the editor, we should pass all the features config (per block as well) and handle it in useFeature properly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, that's my next step.

}

/**
* Adds the necessary data for the Global Styles client UI to the block settings.
*
Expand All @@ -591,7 +606,11 @@ function gutenberg_experimental_global_styles_settings( $settings ) {
// Add the styles for the editor via the settings
// so they get processed as if they were added via add_editor_styles:
// they will get the editor wrapper class.
$settings['styles'][] = array( 'css' => gutenberg_experimental_global_styles_get_stylesheet() );
$merged = gutenberg_experimental_global_styles_get_merged_origins();
$stylesheet = gutenberg_experimental_global_styles_resolver( $merged );
$settings['styles'][] = array( 'css' => $stylesheet );

$settings['__experimentalFeatures'] = gutenberg_experimental_global_styles_get_editor_features( $merged );

return $settings;
}
Expand Down
1 change: 0 additions & 1 deletion lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,4 @@ function gutenberg_is_experiment_enabled( $name ) {
require dirname( __FILE__ ) . '/customizer.php';
require dirname( __FILE__ ) . '/edit-site-page.php';
require dirname( __FILE__ ) . '/edit-site-export.php';
require dirname( __FILE__ ) . '/editor-features.php';
require dirname( __FILE__ ) . '/global-styles.php';