diff --git a/lib/compat.php b/lib/compat.php index cb85b3e3c72d70..4df03c8bf99b9b 100644 --- a/lib/compat.php +++ b/lib/compat.php @@ -30,56 +30,6 @@ function gutenberg_safe_style_css_column_flex_basis( $attr ) { } add_filter( 'safe_style_css', 'gutenberg_safe_style_css_column_flex_basis' ); -/** - * Shim that hooks into `pre_render_block` so as to override `render_block` - * with a function that passes `render_callback` the block object as the - * argument. - * - * @see https://core.trac.wordpress.org/ticket/48104 - * - * @param string $pre_render The pre-rendered content. Default null. - * @param array $block The block being rendered. - * - * @return string String of rendered HTML. - */ -function gutenberg_provide_render_callback_with_block_object( $pre_render, $block ) { - global $post; - if ( 'core/navigation' !== $block['blockName'] ) { - return $pre_render; - } - - $source_block = $block; - - /** This filter is documented in src/wp-includes/blocks.php */ - $block = apply_filters( 'render_block_data', $block, $source_block ); - - $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] ); - $is_dynamic = $block['blockName'] && null !== $block_type && $block_type->is_dynamic(); - $block_content = ''; - $index = 0; - - foreach ( $block['innerContent'] as $chunk ) { - $block_content .= is_string( $chunk ) ? $chunk : render_block( $block['innerBlocks'][ $index++ ] ); - } - - if ( ! is_array( $block['attrs'] ) ) { - $block['attrs'] = array(); - } - - if ( $is_dynamic ) { - $global_post = $post; - - $prepared_attributes = $block_type->prepare_attributes_for_render( $block['attrs'] ); - $block_content = (string) call_user_func( $block_type->render_callback, $prepared_attributes, $block_content, $block ); - - $post = $global_post; - } - - /** This filter is documented in src/wp-includes/blocks.php */ - return apply_filters( 'render_block', $block_content, $block ); -} -add_filter( 'pre_render_block', 'gutenberg_provide_render_callback_with_block_object', 10, 2 ); - /** * Sets the current post for usage in template blocks. * diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index ddf0e2a23662db..6270db2d86bffd 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -122,13 +122,18 @@ function render_submenu_icon() { /** * Renders the `core/navigation` block on server. * - * @param array $attributes The block attributes. * @param array $content The saved content. * @param array $block The parsed block. * * @return string Returns the post content with the legacy widget added. */ -function render_block_navigation( $attributes, $content, $block ) { +function render_block_navigation( $content, $block ) { + + if ( 'core/navigation' !== $block['blockName'] ) { + return $content; + } + + $attributes = $block['attrs']; $block['innerBlocks'] = gutenberg_remove_empty_navigation_links_recursive( $block['innerBlocks'] ); if ( empty( $block['innerBlocks'] ) ) { @@ -234,7 +239,7 @@ function build_navigation_html( $attributes, $block, $colors, $font_sizes, $is_l $html .= ''; // Append submenu icon to top-level item. - if ( $attributes['showSubmenuIcon'] && $is_level_zero && $has_submenu ) { + if ( ! empty( $attributes['showSubmenuIcon'] ) && $is_level_zero && $has_submenu ) { $html .= '' . render_submenu_icon() . ''; } @@ -261,7 +266,7 @@ function register_block_core_navigation() { register_block_type( 'core/navigation', array( - 'attributes' => array( + 'attributes' => array( 'className' => array( 'type' => 'string', ), @@ -291,9 +296,8 @@ function register_block_core_navigation() { 'default' => false, ), ), - - 'render_callback' => 'render_block_navigation', ) ); } add_action( 'init', 'register_block_core_navigation' ); +add_filter( 'render_block', 'render_block_navigation', 10, 2 );