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

Plugin: Extract block editor styles replacement as filter #13625

Merged
merged 3 commits into from
Feb 18, 2019

Conversation

aduth
Copy link
Member

@aduth aduth commented Jan 31, 2019

Extracted from: #13569
Related: #9008

This pull request seeks to implement Gutenberg's replacement editor-styles setting value as a filter on block_settings. This was allow for compatibility with the core implementation once Gutenberg stops reimplementing its own replacement editor (#13569).

Implementation notes:

The change to assign $styles with ABSPATH . WPINC . '/css/dist/editor/editor-styles.css' is merely meant to provide direct alignment to the core implementation. It's never actually used, since the filtering behavior will substitute the styles with its own implementation. But it needs to exist because the filtering assumes that the styles would be the first entry of the default $settings['styles'] array. Unfortunately, we must operate on assumptions since the entries of styles are the contents of the stylesheets themselves, not named or assigned as paths. An alternative implementation could consider reading from the ABSPATH . WPINC to find and substitute the value by the actual file contents assigned, but there'd be a small amount of overhead in reading from the filesystem.

Testing instructions:

Verify that the contents of the built copy of packages/editor/src/editor-styles are present on the page. This may require inspecting the source of the page. It's easier to verify that it's in-fact the Gutenberg copy by making a change to the source file and rebuilding it.

Additionally, verify that the separate locale font family assignment (font-family: 'Noto Serif') is not impacted by these changes, meaning that it is still present and occurs after the editor-styles.css.

@aduth aduth added the Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts label Jan 31, 2019
@aduth aduth added this to In Progress in Remove PHP via automation Jan 31, 2019
@gziolo gziolo added this to the 5.1 (Gutenberg) milestone Feb 7, 2019
@aduth aduth requested a review from a team February 8, 2019 20:29
* own custom styles, it's assumed that the first entry of the styles
* setting should be the default (core) stylesheet.
*/
array_shift( $settings['styles'] );
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it's simpler to just loop over the styles are replace the core editor styles if found (checking the path or something).

Copy link
Member Author

@aduth aduth Feb 14, 2019

Choose a reason for hiding this comment

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

replace the core editor styles if found (checking the path or something).

The problem is that the array contains only the CSS string, no file paths.

It looks something like:

$settings = array(
	'styles' => array(
		array( 'css' => 'body { /* ... */ }' )
	)
);

So we've got nothing to work from to know whether it's the core style, unless we explicitly (re-)read the ABSPATH . WPINC . '/css/dist/editor/editor-styles.css' file from disk and compare it with the array style contents.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's just do that.

@aduth aduth requested a review from gziolo as a code owner February 14, 2019 17:23
@aduth
Copy link
Member Author

aduth commented Feb 14, 2019

Default styles matching made more reliable in d4be401 by exact file contents match.

Fun testing instructions:

echo "* { font-family: \"Comic Sans MS\", cursive, sans-serif \!important; }" >> build/editor/editor-styles.css

@noisysocks noisysocks merged commit b8b26d4 into master Feb 18, 2019
Remove PHP automation moved this from In Progress to Done Feb 18, 2019
@noisysocks noisysocks deleted the update/extend-block-editor-styles branch February 18, 2019 00:53
youknowriad pushed a commit that referenced this pull request Mar 6, 2019
* Plugin: Extract block editor styles replacement as filter

* Plugin: Override default styles by exact file contents match

* Plugin: Fix editor styles prepend behavior
youknowriad pushed a commit that referenced this pull request Mar 6, 2019
* Plugin: Extract block editor styles replacement as filter

* Plugin: Override default styles by exact file contents match

* Plugin: Fix editor styles prepend behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts
Projects
No open projects
Remove PHP
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants