-
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
Custom Navigation blocks, appearing outside the UL on the frontend #49394
Comments
@draganescu I was wondering if we could use HTML Tag Processor to "detect" presence of |
Hi @krugazul how is the custom block added as a possible child of navigation? |
@draganescu The PR description was missing clear testing instructions as was the Core Trac ticket. Here is an example from @costdev in WP Slack: <?php
/**
* Plugin Name: 1. Test 57992
* Description: Tests 57992
* Author: WordPress Core Contributors
* Author URI: https://make.wordpress.org/core
* License: GPLv2 or later
* Version: 1.0.0
*/
add_filter(
'block_core_navigation_render_inner_blocks',
function( $inner_blocks ) {
$inner_blocks[] = new My_Block( array( 'blockName' => 'costdev/my-block' ) );
return $inner_blocks;
},
999
);
class My_Block extends WP_Block {
public function render( $options = array() ) {
return 'My Block!';
}
} |
This seems a bit weird because it actually shouldn't work so it's expected that it doesn't work :) There is a list of allowed blocks for a reason, so if the block cannot be added in the editor it is not expected when rendering. The renderer should only meet blocks that can be added by the user. This is how it is today. If the allowed blocks is something that can be made extendable, that is something to address then. I think not only the navigation block but all blocks that have an allowed list of inner blocks should not be forced to render things outside of that list and behave correctly. |
@draganescu Do we need to improve the docs around |
Maybe 🤷🏻 - I don't think it's specific to the navigation block, it's basically an undocumented assumption. I have proposed in the past cc @gziolo that we bubble up allowed blocks into Either way hacking block content at render time is something we've hit in the past as well - I remember we removed recursively added navigation blocks and that broke the parser :) |
As far as I remember, we landed #37998 that added the |
Description
When assigning a custom block to the navigation block, the
render_block_core_navigation
outputs the custom block outside of theUL
, when on the frontend.Trac Ticket - https://core.trac.wordpress.org/ticket/57992
Source
This array of nav "list items" and "items needing a list wrapper" is defined here
The custom block is included in the $inner_blocks variable. But when it loops through them, the custom block triggers the closing of the
<ul>
prematurely.That is because a custom block, fails the list item check here.
Step-by-step reproduction instructions
Before you start, you will need a custom block that can be added to the
core/navigation
block.Screenshots, screen recording, code snippet
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: