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

Move editor settings code to compat folder #39030

Merged
merged 12 commits into from
Feb 25, 2022

Conversation

oandregal
Copy link
Member

@oandregal oandregal commented Feb 23, 2022

This PR continues with the work of moving PHP code to the corresponding lib/compat folder so it's easier to do the backports and we have a path to remove PHP code from the plugin.

Specifically:

  • Moves the editor settings to lib/compat/6.0 => we've done some modifications to the underlying allowed theme.json to be landed in 6.0 and we need the editors to be aware of them (by using the gutenberg_* functions), that's why this needs to be moved to the 6.0 folder.
  • Extracts to a new file to live in lib/compat/experimental the changes we're still unclear about (gutenberg_get_block_editor_settings_mobile) and that should land together with the settings REST endpoint.

Follow-ups:

  • While investigating this I've realized that WordPress core passes both styles and __experimentalFeatures to any caller of this function, including the site editor (see). However, in the plugin, we do not pass styles to the site editor or mobile because they don't use them. We need to figure out a way forward for this in a follow-up PR. In the meantime, this PR doesn't change this behavior.

How to test

Verify that tests pass.

@oandregal oandregal self-assigned this Feb 23, 2022
@oandregal oandregal added Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Status] In Progress Tracking issues with work in progress labels Feb 23, 2022
@oandregal oandregal force-pushed the update/editor-settings-to-compat-folder branch from a725b3e to 64ffed5 Compare February 24, 2022 13:09
We need the editor settings to use the plugin code until
the minimim WordPress version is 6.0.
*
* @return array New block editor settings.
*/
function gutenberg_get_block_editor_settings_mobile( $settings ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This has been extracted to the experimental folder because we don't know yet what's going to happen with the REST Endpoint this method complements. To land in core in the same release as the endpoint.

}

// Copied from get_block_editor_settings() at wordpress-develop/block-editor.php.
$settings['__experimentalFeatures'] = gutenberg_get_global_settings();
Copy link
Member Author

Choose a reason for hiding this comment

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

We've done some modifications to the data available in theme.json that we expect to land in 6.0. While this doesn't have any changes with respect to what's in WordPress core, we still need to make sure this calls the gutenberg_* methods so the said modifications are loaded in the editors.

$context = 'mobile';
}

if ( 'mobile' === $context && WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This has been extracted to a separate file, see https://github.com/WordPress/gutenberg/pull/39030/files#r814083346

}
if ( isset( $settings['__experimentalFeatures']['spacing']['units'] ) ) {
$settings['enableCustomUnits'] = $settings['__experimentalFeatures']['spacing']['units'];
unset( $settings['__experimentalFeatures']['spacing']['units'] );
Copy link
Member Author

@oandregal oandregal Feb 24, 2022

Choose a reason for hiding this comment

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

This PR brings back this unset line.

This line had been accidentally removed in #32898 while backporting changes from this core patch https://core.trac.wordpress.org/changeset/51203 (note how the core patch still had the unset but it was removed in the Gutenberg PR).

if ( isset( $settings['__experimentalFeatures']['typography']['fontSizes'] ) ) {
$font_sizes_by_origin = $settings['__experimentalFeatures']['typography']['fontSizes'];
$settings['fontSizes'] = isset( $font_sizes_by_origin['custom'] ) ?
$font_sizes_by_origin['custom'] : (
Copy link
Member Author

@oandregal oandregal Feb 24, 2022

Choose a reason for hiding this comment

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

This PR also fixes a typo. Instead of custom this had user.

When we renamed from user to custom we missed this key. In core was properly ported.

@oandregal oandregal changed the title Update/editor settings to compat folder Move editor settings code to compat folder Feb 24, 2022
@oandregal oandregal added [Type] Code Quality Issues or PRs that relate to code quality and removed [Status] In Progress Tracking issues with work in progress labels Feb 24, 2022
@oandregal oandregal marked this pull request as ready for review February 24, 2022 17:23
@oandregal oandregal requested review from a team and removed request for a team February 24, 2022 17:23
Copy link
Contributor

@draganescu draganescu left a comment

Choose a reason for hiding this comment

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

This LGTM!

@oandregal oandregal merged commit d60ab14 into trunk Feb 25, 2022
@oandregal oandregal deleted the update/editor-settings-to-compat-folder branch February 25, 2022 12:21
@github-actions github-actions bot added this to the Gutenberg 12.8 milestone Feb 25, 2022
defined( 'REST_REQUEST' ) &&
REST_REQUEST &&
isset( $_GET['context'] ) &&
'mobile' === $_GET['context']
Copy link
Member Author

Choose a reason for hiding this comment

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

This missed a check, see #39806

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants