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

Fix fatal error when calling undefined block library function. #56459

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions lib/compat/wordpress-6.5/class-wp-navigation-block-renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private static function get_inner_blocks_html( $attributes, $inner_blocks ) {
// Add directives to the submenu if needed.
if ( $has_submenus && $should_load_view_script ) {
$tags = new WP_HTML_Tag_Processor( $inner_blocks_html );
$inner_blocks_html = block_core_navigation_add_directives_to_submenu( $tags, $attributes );
$inner_blocks_html = gutenberg_block_core_navigation_add_directives_to_submenu( $tags, $attributes );
}

return $inner_blocks_html;
Expand All @@ -195,7 +195,7 @@ private static function get_inner_blocks_from_navigation_post( $attributes ) {

// 'parse_blocks' includes a null block with '\n\n' as the content when
// it encounters whitespace. This code strips it.
$compacted_blocks = block_core_navigation_filter_out_empty_blocks( $parsed_blocks );
$compacted_blocks = gutenberg_block_core_navigation_filter_out_empty_blocks( $parsed_blocks );
Copy link
Contributor

Choose a reason for hiding this comment

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

@scruffian I'm seeing that these references have reverted to block_ prefix in Gutenberg trunk. Can you verify if that was intentional so that we can avoid any regressions here 🙏

Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding is that this is now ok because functions being called are now within block-library and indeed within the same file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that's my understanding too, so I think this is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that's ok! What we shouldn't have is gutenberg_ prefixed functions in block-library.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a good point. I think that's what must have drawn my attention to this change.

@scruffian why are we now using gutenberg_ prefix? Should this be revised as @tellthemachines indicates?

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have the gutenberg_ prefix in the navigation block except where its added by the webpack script.


// TODO - this uses the full navigation block attributes for the
// context which could be refined.
Expand All @@ -210,7 +210,7 @@ private static function get_inner_blocks_from_navigation_post( $attributes ) {
* @return WP_Block_List Returns the inner blocks for the navigation block.
*/
private static function get_inner_blocks_from_fallback( $attributes ) {
$fallback_blocks = block_core_navigation_get_fallback_blocks();
$fallback_blocks = gutenberg_block_core_navigation_get_fallback_blocks();

// Fallback my have been filtered so do basic test for validity.
if ( empty( $fallback_blocks ) || ! is_array( $fallback_blocks ) ) {
Expand Down Expand Up @@ -245,9 +245,9 @@ private static function get_inner_blocks( $attributes, $block ) {
defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN &&
array_key_exists( '__unstableLocation', $attributes ) &&
! array_key_exists( 'ref', $attributes ) &&
! empty( block_core_navigation_get_menu_items_at_location( $attributes['__unstableLocation'] ) )
! empty( gutenberg_block_core_navigation_get_menu_items_at_location( $attributes['__unstableLocation'] ) )
) {
$inner_blocks = block_core_navigation_get_inner_blocks_from_unstable_location( $attributes );
$inner_blocks = gutenberg_block_core_navigation_get_inner_blocks_from_unstable_location( $attributes );
}

// Load inner blocks from the navigation post.
Expand All @@ -270,7 +270,7 @@ private static function get_inner_blocks( $attributes, $block ) {
*/
$inner_blocks = apply_filters( 'block_core_navigation_render_inner_blocks', $inner_blocks );

$post_ids = block_core_navigation_get_post_ids( $inner_blocks );
$post_ids = gutenberg_block_core_navigation_get_post_ids( $inner_blocks );
if ( $post_ids ) {
_prime_post_caches( $post_ids, false, false );
}
Expand Down Expand Up @@ -353,8 +353,8 @@ private static function get_layout_class( $attributes ) {
private static function get_classes( $attributes ) {
// Restore legacy classnames for submenu positioning.
$layout_class = static::get_layout_class( $attributes );
$colors = block_core_navigation_build_css_colors( $attributes );
$font_sizes = block_core_navigation_build_css_font_sizes( $attributes );
$colors = gutenberg_block_core_navigation_build_css_colors( $attributes );
$font_sizes = gutenberg_block_core_navigation_build_css_font_sizes( $attributes );
$is_responsive_menu = static::is_responsive( $attributes );

// Manually add block support text decoration as CSS class.
Expand All @@ -378,8 +378,8 @@ private static function get_classes( $attributes ) {
* @return string Returns the styles for the navigation block.
*/
private static function get_styles( $attributes ) {
$colors = block_core_navigation_build_css_colors( $attributes );
$font_sizes = block_core_navigation_build_css_font_sizes( $attributes );
$colors = gutenberg_block_core_navigation_build_css_colors( $attributes );
$font_sizes = gutenberg_block_core_navigation_build_css_font_sizes( $attributes );
$block_styles = isset( $attributes['styles'] ) ? $attributes['styles'] : '';
return $block_styles . $colors['inline_styles'] . $font_sizes['inline_styles'];
}
Expand All @@ -394,7 +394,7 @@ private static function get_styles( $attributes ) {
*/
private static function get_responsive_container_markup( $attributes, $inner_blocks, $inner_blocks_html ) {
$should_load_view_script = static::should_load_view_script( $attributes, $inner_blocks );
$colors = block_core_navigation_build_css_colors( $attributes );
$colors = gutenberg_block_core_navigation_build_css_colors( $attributes );
$modal_unique_id = wp_unique_id( 'modal-' );

$is_hidden_by_default = isset( $attributes['overlayMenu'] ) && 'always' === $attributes['overlayMenu'];
Expand Down Expand Up @@ -627,7 +627,7 @@ public static function render( $attributes, $content, $block ) {

$inner_blocks = static::get_inner_blocks( $attributes, $block );
// Prevent navigation blocks referencing themselves from rendering.
if ( block_core_navigation_block_contains_core_navigation( $inner_blocks ) ) {
if ( gutenberg_block_core_navigation_block_contains_core_navigation( $inner_blocks ) ) {
return '';
}

Expand Down
Loading