Skip to content

Commit

Permalink
Navigation: Update the navigaiton renderer class name so that it does…
Browse files Browse the repository at this point in the history
…n't clash with the one backported to core (#58429)

* Navigation: Move the renderer class to the main navigation file (#57979)

* Navigation: Move the renderer class to the main navigation file to take advantage of the automatic backporting

* Update the build script to also copy over class files

* prefix with gutenberg

* Add a Gutenberg suffix to class files when they are built

* add gutenberg prefix to functions

* move the built block files to their own dir

* Putting back the render class into the same file as the navigation block

* Update the rendered post rebase

* Fix php unit tests

---------

Co-authored-by: Riad Benguella <[email protected]>

* Use the right renderer class

* Fix php unit tests (after variations api change) (#58090)

---------

Co-authored-by: Riad Benguella <[email protected]>
Co-authored-by: Ella <[email protected]>
  • Loading branch information
3 people authored Jan 30, 2024
1 parent 3c5da03 commit 75a8d1a
Show file tree
Hide file tree
Showing 8 changed files with 712 additions and 677 deletions.
664 changes: 0 additions & 664 deletions lib/compat/wordpress-6.5/class-wp-navigation-block-renderer.php

This file was deleted.

1 change: 0 additions & 1 deletion lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ function gutenberg_is_experiment_enabled( $name ) {

// WordPress 6.5 compat.
require __DIR__ . '/compat/wordpress-6.5/block-patterns.php';
require __DIR__ . '/compat/wordpress-6.5/class-wp-navigation-block-renderer.php';
require __DIR__ . '/compat/wordpress-6.5/kses.php';

// Experimental features.
Expand Down
31 changes: 30 additions & 1 deletion packages/block-library/src/navigation-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,36 @@ function register_block_core_navigation_link_variation( $variation ) {
return;
}

$navigation_block_type->variations[] = $variation;
$navigation_block_type->variations = array_merge(
$navigation_block_type->variations,
array( $variation )
);
}

/**
* Unregister a variation for a post type / taxonomy for the navigation link block.
*
* @param string $name Name of the post type / taxonomy (which was used as variation name).
* @return void
*/
function block_core_navigation_link_unregister_variation( $name ) {
// Directly get the variations from the registered block type
// because there's no server side (un)registration for variations (see #47170).
$navigation_block_type = WP_Block_Type_Registry::get_instance()->get_registered( 'core/navigation-link' );
// If the block is not registered (yet), there's no need to remove a variation.
if ( ! $navigation_block_type || empty( $navigation_block_type->variations ) ) {
return;
}
$variations = $navigation_block_type->variations;
// Search for the variation and remove it from the array.
foreach ( $variations as $i => $variation ) {
if ( $variation['name'] === $name ) {
unset( $variations[ $i ] );
break;
}
}
// Reindex array after removing one variation.
$navigation_block_type->variations = array_values( $variations );
}

/**
Expand Down
Loading

0 comments on commit 75a8d1a

Please sign in to comment.