-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add/dynamic navigation block #16796
Merged
Merged
Add/dynamic navigation block #16796
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
72c6c38
dynamic navigation block and hierarchy attributes
draganescu 850252e
removed the CSS hiding the inserter
draganescu 13e88c0
Navigation: Remove hierarchy attribute, pass $block to render_callback
noisysocks bfe4c44
sample walker
draganescu 1cf07e9
gave up the walker class
draganescu 38f692a
removed superfluous argument
draganescu 5986a5a
comment fix
draganescu 74c1a41
another comment fix
draganescu 44972f4
PHP lint
draganescu fe66541
fixtures fix
draganescu e3daf30
Update packages/block-library/src/navigation-menu/index.php
draganescu 2a571d2
Update packages/block-library/src/navigation-menu/index.php
draganescu 0df6c3a
renamed block html renderer, simplified menu item save
draganescu 5a8b380
fixed booleans as strings
draganescu 9256d63
added missing classname
draganescu 8994c2f
fixed fixtures with missing class
draganescu 95939d3
attempt to make HTML identical
draganescu 73cb901
saving only comments as HTML in the DB b/c InnerBlocks are not ready …
draganescu 3bea660
fixtures
draganescu d4dcba6
Remove unnecessary space from generated HTML
noisysocks e57fcd3
Remove unnecessary whitespace
noisysocks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
InnerBlocks, | ||
} from '@wordpress/block-editor'; | ||
|
||
export default function save( { attributes } ) { | ||
return ( | ||
draganescu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<a | ||
href={ attributes.destination } | ||
rel={ attributes.nofollow && 'nofollow' } | ||
title={ attributes.title } | ||
target={ attributes.opensInNewTab && '_blank' } | ||
> | ||
{ attributes.label } | ||
</a> | ||
<> | ||
<a | ||
href={ attributes.destination } | ||
rel={ attributes.nofollow && 'nofollow' } | ||
title={ attributes.title } | ||
target={ attributes.opensInNewTab && '_blank' } | ||
> | ||
{ attributes.label } | ||
</a> | ||
<InnerBlocks.Content /> | ||
</> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* Server-side rendering of the `core/navigation-menu` block. | ||
* | ||
* @package WordPress | ||
draganescu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
|
||
/** | ||
* Renders the `core/navigation-menu` 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_menu( $attributes, $content, $block ) { | ||
return prepare_navigation( $block ); | ||
} | ||
|
||
/** | ||
* Walks the inner block structure and retunrs an HTML list of it. | ||
draganescu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @param array $block The block. | ||
* | ||
* @return string Returns an HTML list from innerBlocks. | ||
*/ | ||
function prepare_navigation( $block ) { | ||
draganescu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$block_tree = ''; | ||
draganescu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
foreach ( (array) $block['innerBlocks'] as $key => $menu_item ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we check that |
||
$block_tree .= '<li>' . $menu_item['innerContent'][0]; | ||
if ( count( (array) $menu_item['innerBlocks'] ) > 0 ) { | ||
draganescu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$block_tree .= prepare_navigation( $menu_item ); | ||
} | ||
$block_tree .= '</li>'; | ||
} | ||
return '<ul>' . $block_tree . '</ul>'; | ||
} | ||
|
||
/** | ||
* Register the navigation menu block. | ||
*/ | ||
function register_block_core_navigation_menu() { | ||
register_block_type( | ||
'core/navigation-menu', | ||
array( | ||
'category' => 'layout', | ||
'attributes' => array( | ||
'automaticallyAdd' => array( | ||
'type' => 'boolean', | ||
'default' => 'false', | ||
draganescu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
), | ||
), | ||
'render_callback' => 'render_block_navigation_menu', | ||
) | ||
); | ||
} | ||
|
||
add_action( 'init', 'register_block_core_navigation_menu' ); |
2 changes: 1 addition & 1 deletion
2
packages/e2e-tests/fixtures/blocks/core__navigation-menu-item.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<!-- wp:navigation-menu-item {"label":"WordPress","destination":"https://wordpress.org/"} --> | ||
<a class="wp-block-navigation-menu-item" href="https://wordpress.org/">WordPress</a> | ||
draganescu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<a href="https://wordpress.org/">WordPress</a> | ||
<!-- /wp:navigation-menu-item --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/e2e-tests/fixtures/blocks/core__navigation-menu-item.serialized.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<!-- wp:navigation-menu-item {"label":"WordPress","destination":"https://wordpress.org/"} --> | ||
<a href="https://wordpress.org/" class="wp-block-navigation-menu-item">WordPress</a> | ||
<a href="https://wordpress.org/">WordPress</a> | ||
<!-- /wp:navigation-menu-item --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<!-- wp:navigation-menu --> | ||
<nav class="wp-block-navigation-menu"> | ||
<!-- wp:navigation-menu-item {"label":"WordPress","destination":"https://wordpress.org/"} --> | ||
<a class="wp-block-navigation-menu-item" href="https://wordpress.org/">WordPress</a> | ||
<a href="https://wordpress.org/">WordPress</a> | ||
<!-- /wp:navigation-menu-item --> | ||
</nav> | ||
<!-- /wp:navigation-menu --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/e2e-tests/fixtures/blocks/core__navigation-menu.serialized.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<!-- wp:navigation-menu --> | ||
<nav class="wp-block-navigation-menu"><!-- wp:navigation-menu-item {"label":"WordPress","destination":"https://wordpress.org/"} --> | ||
<a href="https://wordpress.org/" class="wp-block-navigation-menu-item">WordPress</a> | ||
<a href="https://wordpress.org/">WordPress</a> | ||
<!-- /wp:navigation-menu-item --></nav> | ||
<!-- /wp:navigation-menu --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"core\/archives":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/calendar":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"month":{"type":"integer"},"year":{"type":"integer"}}},"core\/categories":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showHierarchy":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/latest-comments":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"commentsToShow":{"type":"number","default":5,"minimum":1,"maximum":100},"displayAvatar":{"type":"boolean","default":true},"displayDate":{"type":"boolean","default":true},"displayExcerpt":{"type":"boolean","default":true}}},"core\/latest-posts":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"categories":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostContent":{"type":"boolean","default":false},"displayPostContentRadio":{"type":"string","default":"excerpt"},"excerptLength":{"type":"number","default":55},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}},"core\/legacy-widget":{"attributes":{"identifier":{"type":"string"},"instance":{"type":"object"},"isCallbackWidget":{"type":"boolean"}}},"core\/rss":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"columns":{"type":"number","default":2},"blockLayout":{"type":"string","default":"list"},"feedURL":{"type":"string","default":""},"itemsToShow":{"type":"number","default":5},"displayExcerpt":{"type":"boolean","default":false},"displayAuthor":{"type":"boolean","default":false},"displayDate":{"type":"boolean","default":false},"excerptLength":{"type":"number","default":55}}},"core\/search":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"label":{"type":"string","default":"Search"},"placeholder":{"type":"string","default":""},"buttonText":{"type":"string","default":"Search"}}},"core\/shortcode":{"attributes":{"text":{"type":"string","source":"html"}}},"core\/tag-cloud":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"taxonomy":{"type":"string","default":"post_tag"},"showTagCounts":{"type":"boolean","default":false}}}} | ||
{"core\/archives":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/calendar":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"month":{"type":"integer"},"year":{"type":"integer"}}},"core\/categories":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showHierarchy":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/latest-comments":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"commentsToShow":{"type":"number","default":5,"minimum":1,"maximum":100},"displayAvatar":{"type":"boolean","default":true},"displayDate":{"type":"boolean","default":true},"displayExcerpt":{"type":"boolean","default":true}}},"core\/latest-posts":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"categories":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostContent":{"type":"boolean","default":false},"displayPostContentRadio":{"type":"string","default":"excerpt"},"excerptLength":{"type":"number","default":55},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}},"core\/legacy-widget":{"attributes":{"identifier":{"type":"string"},"instance":{"type":"object"},"isCallbackWidget":{"type":"boolean"}}},"core\/navigation-menu":{"category":"layout","attributes":{"automaticallyAdd":{"type":"boolean","default":"false"}}},"core\/rss":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"columns":{"type":"number","default":2},"blockLayout":{"type":"string","default":"list"},"feedURL":{"type":"string","default":""},"itemsToShow":{"type":"number","default":5},"displayExcerpt":{"type":"boolean","default":false},"displayAuthor":{"type":"boolean","default":false},"displayDate":{"type":"boolean","default":false},"excerptLength":{"type":"number","default":55}}},"core\/search":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"label":{"type":"string","default":"Search"},"placeholder":{"type":"string","default":""},"buttonText":{"type":"string","default":"Search"}}},"core\/shortcode":{"attributes":{"text":{"type":"string","source":"html"}}},"core\/tag-cloud":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"taxonomy":{"type":"string","default":"post_tag"},"showTagCounts":{"type":"boolean","default":false}}}} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once merged, let's remember to create a Trac ticket to update WP Core with these changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could create the ticket now, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep go for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a ticket already for that? Should we land it in 5.3 to avoid forgetting about it later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://core.trac.wordpress.org/ticket/48104 - just made this.