-
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: load collection JSON data from a URL in the collection config #54067
Conversation
Co-authored-by: Tonya Mork <tonya.mork@automattic.com>
* Ensures each required param is of the right data type. * Improves each param check error to include expected data type.
* Rechecking if "data_json_file" exists in the $config property shouldn't be necessary, as it's checked in the constructor. * If the file does not exist, bail out immediately as there's nothing more to do. * Adds a check and WP_Error for file_get_contents(): file_get_contents() returns false on failure. If there's nothing in the file, an empty string is returned. This change checks for both of these conditions and returns a WP_Error if either happens. * Internationalizes WP_Error error message for consistency in Core.
Co-authored-by: Tonya Mork <tonya.mork@automattic.com>
Co-authored-by: Tonya Mork <tonya.mork@automattic.com>
Co-authored-by: Tonya Mork <tonya.mork@automattic.com>
This reverts commit 0e6c026.
…n, remove try catch and raise the error if needed
Flaky tests detected in a047eb7. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6253897039
|
This PR was updated with the latest trunk changes. It seems ready to review. |
Works for me 👍🏻 Test ReportSteps to Test
Environment
Actual Results
|
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.
Please find my code review below.
lib/experimental/fonts/font-library/class-wp-font-collection.php
Outdated
Show resolved
Hide resolved
Co-authored-by: Anton Vlasenko <43744263+anton-vlasenko@users.noreply.github.com>
Co-authored-by: Anton Vlasenko <43744263+anton-vlasenko@users.noreply.github.com>
Co-authored-by: Anton Vlasenko <43744263+anton-vlasenko@users.noreply.github.com>
@anton-vlasenko I committed your code changes. |
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.
🚢
…config (#54067) * Adding Font Collection class * php formatting and linting * Adding tests for collections routes * Adding tests for WP_Font_Collection constructor * adding tests for WP_Font_Collection get_data() * adding tests for WP_Font_Library register_font_collection() * get font collection tests * adding 'wp_' prefix to the 'register_font_collection' filter name * fix callback name * making class property private * registering filter from font-library.php file * removing superfluous comment * moving files to according changes in trunk * config without a json file should fail * fix property name in tests * name fix Co-authored-by: Tonya Mork <tonya.mork@automattic.com> * comment update Co-authored-by: Tonya Mork <tonya.mork@automattic.com> * Adds WP_Error to return type * Improves contructor error handling. * Ensures each required param is of the right data type. * Improves each param check error to include expected data type. * FontCollection::get_data(): Improves error handling * Rechecking if "data_json_file" exists in the $config property shouldn't be necessary, as it's checked in the constructor. * If the file does not exist, bail out immediately as there's nothing more to do. * Adds a check and WP_Error for file_get_contents(): file_get_contents() returns false on failure. If there's nothing in the file, an empty string is returned. This change checks for both of these conditions and returns a WP_Error if either happens. * Internationalizes WP_Error error message for consistency in Core. * Removes empty space for wpcs * adding filter in a simpler way Co-authored-by: Tonya Mork <tonya.mork@automattic.com> * micro-optimization Co-authored-by: Tonya Mork <tonya.mork@automattic.com> * reuse WP_Error response instead of creating a new one Co-authored-by: Tonya Mork <tonya.mork@automattic.com> * Eliminates try/catch * Revert "Eliminates try/catch" commit This reverts commit 0e6c026. * Remove wp_register_font_collection and replace it by a global function, remove try catch and raise the error if needed * adding function comment and guard agains re-declaration * php format * fixing docblock coments * removing param comment * re-adding parameter comment removed by mistake * format php * updating WP_Font_Collection __construct tests * updating WP_Font_Collection get_data tests * updating tests * php format * array check Co-authored-by: Tonya Mork <tonya.mork@automattic.com> * Documents config array structure * adding tests for /fonts/collections endpoint * adding /fonts/collections/<id> endpoint test * format * format * add test for missing collection * removing not needed variables * Add more tests and split the test for WP_REST_Font_Library_Controller * lint * try to create dir for tests in CI * renane config property to src and handle URLs apart from file paths * Add the ability to load collection JSON data from a URL * remove unwanted comment * fix missing merge * fix merge with trunk * removing test file after merge with trunk * removing duplicated test files after merge with trunk * decode data to make availanle in the client as json * update google fonts collection source * format php' * removing the default font collection (google fonts) json file from repo * fixing logic to get data from url * add tests to try the font collection fetching from url * update test * format comments * replacing existing url in test with a mock url * early return Co-authored-by: Anton Vlasenko <43744263+anton-vlasenko@users.noreply.github.com> * remove not needed filter Co-authored-by: Anton Vlasenko <43744263+anton-vlasenko@users.noreply.github.com> * rewording error message Co-authored-by: Anton Vlasenko <43744263+anton-vlasenko@users.noreply.github.com> --------- Co-authored-by: Tonya Mork <tonya.mork@automattic.com> Co-authored-by: Anton Vlasenko <43744263+anton-vlasenko@users.noreply.github.com>
I just cherry-picked this PR to the release/16.7 branch to get it included in the next release: ead73c8 |
Oops, this has already been merged. if ( false !== strpos( $this->config['src'], 'http' ) && false !== strpos( $this->config['src'], '://' ) ) { could be replaced with if ( str_contains( $this->config['src'], 'http' ) && str_contains( $this->config['src'], '://' ) ) { for better readability. |
Thank yo so much for the new review @anton-vlasenko !
|
@matiasbenedetto, this should be okay, as a polyfill for str_contains was introduced to Core in https://core.trac.wordpress.org/ticket/49652. |
@ironprogrammer Good to know. Changed here: #54832 |
What?
Font Library: load collection JSON data from a URL in the collection config.
Why?
To avoid loading Google Fonts collection data from a file in the repo.
How?
data_json_file
property from the font collection config and replace it bysrc
property.src
property can have a value of a URL or a file path.src
is a URLor a file path it will be read by the backend and the data will be sent to the client.Closes #53992
Testing instructions:
Use the UI to load Google Fonts collection:
Depends on:
Disclaimer
We are using this URL to load the google fonts collection data. When that file is hosted in wordpress.org that URL will be replaced.
Tracking issue: