-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Font Library: font collection refactor to use the new schema #57884
Font Library: font collection refactor to use the new schema #57884
Conversation
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ phpunit/tests/fonts/font-library/wpFontCollection/isConfigValid.php ❔ phpunit/tests/fonts/font-library/wpRestFontCollectionsController.php ❔ lib/experimental/fonts/font-library/class-wp-font-collection.php ❔ lib/experimental/fonts/font-library/class-wp-font-library.php ❔ lib/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php ❔ lib/experimental/fonts/font-library/font-library.php ❔ phpunit/tests/fonts/font-library/wpFontCollection/__construct.php ❔ phpunit/tests/fonts/font-library/wpFontCollection/getConfig.php ❔ phpunit/tests/fonts/font-library/wpFontFamily/__construct.php ❔ phpunit/tests/fonts/font-library/wpFontLibrary/registerFontCollection.php ❔ phpunit/tests/fonts/font-library/wpFontCollection/getContent.php |
Size Change: +1.67 kB (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
I'm not sure how to resolve that... But I get that error when running the unit tests. |
I added an ignore for the rule failing on that line: 823a580 |
This looks good to me. Works as I expected and tests seem right. 🚢 |
lib/experimental/fonts/font-library/class-wp-font-collection.php
Outdated
Show resolved
Hide resolved
lib/experimental/fonts/font-library/class-wp-font-collection.php
Outdated
Show resolved
Hide resolved
lib/experimental/fonts/font-library/class-wp-font-collection.php
Outdated
Show resolved
Hide resolved
lib/experimental/fonts/font-library/class-wp-font-collection.php
Outdated
Show resolved
Hide resolved
Co-authored-by: Jeff Ong <jonger4@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few initial comments. Will review more fully later today!
lib/experimental/fonts/font-library/class-wp-font-collection.php
Outdated
Show resolved
Hide resolved
lib/experimental/fonts/font-library/class-wp-font-collection.php
Outdated
Show resolved
Hide resolved
lib/experimental/fonts/font-library/class-wp-font-collection.php
Outdated
Show resolved
Hide resolved
lib/experimental/fonts/font-library/class-wp-font-collection.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this by installing fonts from the default collection and it worked as expected.
I left a number of suggestions/ideas, but feel free to punt some of those to follow-ups, if you'd like to keep this PR limited to issues around the new schema format.
lib/experimental/fonts/font-library/class-wp-font-collection.php
Outdated
Show resolved
Hide resolved
lib/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php
Outdated
Show resolved
Hide resolved
lib/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php
Outdated
Show resolved
Hide resolved
lib/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php
Outdated
Show resolved
Hide resolved
@@ -134,7 +134,8 @@ function wp_unregister_font_collection( $collection_id ) { | |||
'slug' => 'default-font-collection', | |||
'name' => 'Google Fonts', | |||
'description' => __( 'Add from Google Fonts. Fonts are copied to and served from your site.', 'gutenberg' ), | |||
'src' => 'https://s.w.org/images/fonts/16.7/collections/google-fonts-with-preview.json', | |||
// TODO: This URL needs to be updated to the wporg hosted one prior to the Gutenberg 17.6 release. | |||
'src' => 'https://raw.githubusercontent.com/WordPress/google-fonts-to-wordpress-collection/main/releases/gutenberg-17.6/google-fonts.json', | |||
); | |||
|
|||
wp_register_font_collection( $default_font_collection ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the font collection registered on every request? If the font collection is only needed in wp-admin and rest api requests, maybe there is a hook we can for collection registration.
@@ -62,11 +62,17 @@ public static function get_expected_font_mime_types_per_php_version( $php_versio | |||
* @return WP_Font_Collection|WP_Error A font collection is it was registered successfully and a WP_Error otherwise. | |||
*/ | |||
public static function register_font_collection( $config ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For both register_font_collection
and WP_Font_Collection::__construct
, I think using $slug as the first arg, and then an array of config args second, would be closer to how other register_
functions tend to work (register_post_type, for example).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented in this PR: #58269
Co-authored-by: Grant Kinney <creativecoder@users.noreply.github.com>
…/gutenberg into try/font-collection-new-schema
Thanks for the review. I added most of the suggestions I left out this optimization opportunity and this parameters changes to work on those on follow ups. |
* google fonts collection data provisional url * rename controller methods * fix get_items parameters * fix endpoint return * rafactor font collection class * fix tests for the refactored class * refactor font collections rest controller * update font collection tests * update the frontend to use the new endpoint data schema * format php * adding linter line ignore rul * replacing throwing an exception by calling doing_it_wrong * add translation marks Co-authored-by: Jeff Ong <jonger4@gmail.com> * user ternary operator * correct translation formatting and comments * renaming function * renaming tests * improve url matching Co-authored-by: Grant Kinney <creativecoder@users.noreply.github.com> * return error without rest_ensure_response * fix contradictory if condition --------- Co-authored-by: Jeff Ong <jonger4@gmail.com> Co-authored-by: Grant Kinney <creativecoder@users.noreply.github.com>
* Font Library: add wp_font_face post type and scaffold font face REST API controller (#57656) * Font Library: create font faces through the REST API (#57702) * Refactor Font Family Controller (#57785) * Font Family and Font Face REST API endpoints: better data handling and errors (#57843) * Font Families REST API endpoint: ensure unique font family slugs (#57861) * Font Library: delete child font faces and font assets when deleting parent (#57867) Co-authored-by: Sarah Norris <1645628+mikachan@users.noreply.github.com> * Font Library: refactor client side install functions to work with revised API (#57844) * Add batchInstallFontFaces function and related plumbing. * Fix resolver name. * Add embedding and rebuild theme.json settings for fontFamily. * Handle responses directly, add to collection before activating. Remove unused test. * Remove getIntersectingFontFaces. * Check for existing font family before installing. * Reference src, not uploadedFile key. Co-authored-by: Matias Benedetto <matias.benedetto@gmail.com> * Check for existing font family using GET /font-families?slug=. * Filter already installed font faces (determined by matching fontWeight AND fontStyle) --------- Co-authored-by: Matias Benedetto <matias.benedetto@gmail.com> Co-authored-by: Jason Crist <jcrist@pbking.com> * Cleanup/font library view error handling (#57926) * Add batchInstallFontFaces function and related plumbing. * Fix resolver name. * Add embedding and rebuild theme.json settings for fontFamily. * Handle responses directly, add to collection before activating. Remove unused test. * Remove getIntersectingFontFaces. * Check for existing font family before installing. * Reference src, not uploadedFile key. Co-authored-by: Matias Benedetto <matias.benedetto@gmail.com> * Check for existing font family using GET /font-families?slug=. * Filter already installed font faces (determined by matching fontWeight AND fontStyle) * moved response processing into the resolver for fetchGetFontFamilyBySlug * Moved response processing for font family installation to the resolver * Refactored font face installation process to handle errors more cleanly * Cleanup error handling for font library view * Add i18n function to error messages * Add TODO comment for uninstall notice --------- Co-authored-by: Jeff Ong <jonger4@gmail.com> Co-authored-by: Matias Benedetto <matias.benedetto@gmail.com> Co-authored-by: Sarah Norris <sarah@sekai.co.uk> * Fix unique key prop warning when opening modal * Add key props to FontsGrid children * Font Faces endpoint: prevent creating font faces with duplicate settings (#57903) * Font Library: Update uninstall/delete on client side (#57932) * Fix delete endpoint * Update fetchUninstallFontFamily to match new format * Update uninstallFont * Add uninstall notice back in * Tidy up comments * Re-word uninstall notices * Add spacing to error message * Refactored how font family values were processed so they would retain their id, which is now used to delete a font family without fetching data via slug * Rename uninstallFont to uninstallFontFamily * Throw uninstall errors rather than returning them --------- Co-authored-by: Jason Crist <jcrist@pbking.com> * Add slug/id back to FontCollection * Change tabsFromCollections inline with Font Collections PR * Use child.key for key prop in FontsGrid * Update packages/edit-site/src/components/global-styles/font-library-modal/local-fonts.js Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com> * Font Library: address JS feedback in #57688 (#57961) * Wrap error messages in sprintf * Use await rather than then * Add variables for API URLs * Update packages/edit-site/src/components/global-styles/font-library-modal/resolvers.js Co-authored-by: Jeff Ong <jonger4@gmail.com> --------- Co-authored-by: Jeff Ong <jonger4@gmail.com> * Font Library REST API endpoints: address initial feedback from feature branch (#57946) * Font Library: font collection refactor to use the new schema (#57884) * google fonts collection data provisional url * rename controller methods * fix get_items parameters * fix endpoint return * rafactor font collection class * fix tests for the refactored class * refactor font collections rest controller * update font collection tests * update the frontend to use the new endpoint data schema * format php * adding linter line ignore rul * replacing throwing an exception by calling doing_it_wrong * add translation marks Co-authored-by: Jeff Ong <jonger4@gmail.com> * user ternary operator * correct translation formatting and comments * renaming function * renaming tests * improve url matching Co-authored-by: Grant Kinney <creativecoder@users.noreply.github.com> * return error without rest_ensure_response * fix contradictory if condition --------- Co-authored-by: Jeff Ong <jonger4@gmail.com> Co-authored-by: Grant Kinney <creativecoder@users.noreply.github.com> * Remove old WP_REST_Autosave_Fonts_Controller class --------- Co-authored-by: Grant Kinney <creativecoder@users.noreply.github.com> Co-authored-by: Grant Kinney <hi@grant.mk> Co-authored-by: Jeff Ong <jonger4@gmail.com> Co-authored-by: Matias Benedetto <matias.benedetto@gmail.com> Co-authored-by: Jason Crist <jcrist@pbking.com> Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com>
* Font Library: add wp_font_face post type and scaffold font face REST API controller (#57656) * Font Library: create font faces through the REST API (#57702) * Refactor Font Family Controller (#57785) * Font Family and Font Face REST API endpoints: better data handling and errors (#57843) * Font Families REST API endpoint: ensure unique font family slugs (#57861) * Font Library: delete child font faces and font assets when deleting parent (#57867) * Font Library: refactor client side install functions to work with revised API (#57844) * Cleanup/font library view error handling (#57926) * Font Faces endpoint: prevent creating font faces with duplicate settings (#57903) * Font Library: Update uninstall/delete on client side (#57932) * Font Library: address JS feedback in #57688 (#57961) * Font Library REST API endpoints: address initial feedback from feature branch (#57946) * Font Library: font collection refactor to use the new schema (#57884) * Fix font asset download when font faces are installed (#58021) * Font Families and Faces: disable autosaves using empty class (#58018) * Adds migration for legacy font family content (#58032) --------- Co-authored-by: Jeff Ong <jonger4@gmail.com> Co-authored-by: Matias Benedetto <matias.benedetto@gmail.com> Co-authored-by: Jason Crist <jcrist@pbking.com> Co-authored-by: Sarah Norris <sarah@sekai.co.uk> Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com>
What?
Why?
To be more consistent with other WordPress controllers.
How?
Refactoring frontend and backend to consume the new shape of the data.
Testing Instructions