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 PHP notice shown when rendering a navigation link block #28999

Merged
merged 2 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion packages/block-library/src/navigation-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ function block_core_navigation_link_render_submenu_icon() {
function render_block_core_navigation_link( $attributes, $content, $block ) {
// Don't render the block's subtree if it is a draft.
if (
isset( $attributes['id'] ) && is_numeric( $attributes['id'] ) &&
isset( $attributes['id'] ) &&
is_numeric( $attributes['id'] ) &&
isset( $attributes['type'] ) &&
( 'post' === $attributes['type'] || 'page' === $attributes['type'] )
) {
$post = get_post( $attributes['id'] );
Expand Down
20 changes: 20 additions & 0 deletions phpunit/class-block-library-navigation-link-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,24 @@ function test_returns_link_for_category() {
) !== false
);
}

function test_returns_link_for_plain_link() {
$parsed_blocks = parse_blocks(
'<!-- wp:navigation-link {"label":"My Website","url":"https://example.com"} /-->'
);
$this->assertEquals( 1, count( $parsed_blocks ) );

$navigation_link_block = new WP_Block( $parsed_blocks[0], array() );
$this->assertEquals(
true,
strpos(
gutenberg_render_block_core_navigation_link(
$navigation_link_block->attributes,
array(),
$navigation_link_block
),
'My Website'
) !== false
);
}
}