Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate Navigation fallbacks logic between Editor and Front of Si…
…te via REST API (#48698) * Add Navigation REST class with fallback endpoint * Scaffold out tests * Add fallback creation method and tests * Add tests for returning existing Navigation posts * Use Gutenberg versions of block functions * Add classic meny and concurrent request assertions * Test does not create from classic if Navigation menu exists * Test for page list being unavailable * Extract common Nav fallback code into dedicated class * Remove changes to load * Move get recent navigation into common class * Migrate functions to class and deprecate originals * Refactor method to get fallback to exit early style * Use new class in render_callback * Add example of dedicated class tests over REST endpoint tests * Add example of refactoring editor code to use new API endpoint * Update docblock * Add permissions check and test * Improve comments * Adjust test user * Revert removal of deprecated function bodies * Reinstate deprecations * Update editor notice * Update endpoint to singular form (fallback) * Rename class to be specifically related to fallbacks and non generic * Also update file names * Avoid returning unecessary WP_Error * Avoid get_post and use performance internal method * Normalize functions to standardise signatures * Extract Menu parsing logic into separate class * Refactor classic menu fallback logic * Add test for Classic Menu in Primary Location * Add test for classic menu fallback to “primary” slug * Add further tests for classic menu fallback mechanic * Tidy * Controller docblocks * Docblocks for WP_Navigation_Fallbacks_Gutenberg * Simplfy fallbacks sequence * Tweak error slug * Use array() syntax * Improve function naming for clarity * Try to fix PHPCS errors and warnings * Rename class Resolves https://github.com/WordPress/gutenberg/pull/48698/files#r1147427800 * Correct return type * Update naming for consistency Resolves https://github.com/WordPress/gutenberg/pull/48698/files#r1150229415 * Extract function for default registered blocks * Corrects spelling in comment * Use more appropriate assertion * Remove code references that no longer apply * Remove PHP based ordering. wp_nav_menu applies ordering by default already and keying the menu items by order key seems to be pointless as the key is not used. https://developer.wordpress.org/reference/functions/wp_get_nav_menu_items/#parameters * Rename class to match file This may change later as the Gutenberg suffix may be unnecessary * Move to standalone block editor REST endpoint No longer extends Posts Controller endpoint. * Migrate all tests to the Domain class and remove from REST endpoint tests * Add smoke test to REST endpoint * Augment smoke test to check for number of menus created * Add schema and associated test * Add useful comment * Update editor logic to expect an ID from the REST endpoint * Correct return type * Add default domain to i18n * Try to get the file docblock comment correct * Another file comment update * Update lib/experimental/class-wp-rest-navigation-fallbacks-controller.php Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com> * Update REST method naming to use `get_item` * Move method inline with main permissions check * Ensure rest response for endpoint * Simplify perrmissions checks * Add and translate error messages * Remove erroneous comment * Use static function Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com> * Add @Covers notation * Add messages to assertions * Add messages to all assertions * Remove unused method * Update correct return type * Implement prepare_item_for_response * Revert to returning object in REST response * Adjust tests to assert on new return type * Add response context filtering * Revert to `array` accidentally introduced in refactor Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com> * add an extra comment to keep the linter happy, maybe * Check fields before included them in response Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com> * Improve test name * Update e2e test to expect Page List fallback Menu to be auto-created * Revert fallbacks invocation to simplified method Addresses https://github.com/WordPress/gutenberg/pull/48698/files#r1147610071 * Correct privacy on members of WP_Navigation_Fallbacks_Gutenberg * Rename test and remove associated @doesNotPerformAssertions * Remove unnecessary test for WP_Error * Update comment Co-authored-by: Andrei Draganescu <me@andreidraganescu.info> * Minor comment rewording. Co-authored-by: Andrei Draganescu <me@andreidraganescu.info> * Remove unnecessary comments Co-authored-by: Andrei Draganescu <me@andreidraganescu.info> * Reword comment to align with block terminology Co-authored-by: Andrei Draganescu <me@andreidraganescu.info> * Improve comment wording. Co-authored-by: Andrei Draganescu <me@andreidraganescu.info> * Remove some comments Co-authored-by: Andrei Draganescu <me@andreidraganescu.info> * Rename classes with singular “fallback” * Extract conditional to var for clarity Addresses https://github.com/WordPress/gutenberg/pull/48698/files#r1171571842 * Rename converter class Addresses https://github.com/WordPress/gutenberg/pull/48698/files#r1171568403 * Fix comments in JS * Add comments to improve clarity around fallbacks logic Addresses #48698 (comment) * Shorten method name to reduce verbosity Addresses #48698 (comment) * Remove unnecessary comments from self documenting code Addresses #48698 (comment) * Rename variables for clarity Addresses #48698 (comment) * Fix PHPCS * Make converter class static Follows from discussion at #48698 (comment) * Improve var naming * Ensure all assertions have messages * Add @Covers annotation * Add links to the response * Add test for inclusion of links in Response * Fix PHPCS --------- Co-authored-by: Ben Dwyer <ben@scruffian.com> Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com> Co-authored-by: Andrei Draganescu <me@andreidraganescu.info>
- Loading branch information