Skip to content

Commit

Permalink
removes checking by type
Browse files Browse the repository at this point in the history
also fixes LinkControl to not set URL as if for manual entries
  • Loading branch information
draganescu committed Apr 27, 2020
1 parent 40d3dd2 commit 20558b6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 23 deletions.
1 change: 0 additions & 1 deletion packages/block-editor/src/components/link-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ function LinkControl( {

return Promise.resolve( [
{
id: val,
title: val,
url: type === 'URL' ? prependHTTP( val ) : val,
type,
Expand Down
3 changes: 0 additions & 3 deletions packages/block-library/src/navigation-link/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
"type": "boolean",
"default": false
},
"type": {
"type": "string"
},
"description": {
"type": "string"
},
Expand Down
4 changes: 1 addition & 3 deletions packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ function NavigationLinkEdit( {
title: newTitle = '',
url: newURL = '',
opensInNewTab: newOpensInNewTab,
type,
id,
} = {} ) =>
setAttributes( {
Expand Down Expand Up @@ -273,8 +272,7 @@ function NavigationLinkEdit( {
return escape( normalizedURL );
} )(),
opensInNewTab: newOpensInNewTab,
type,
id,
id: id ? Number( id ) : undefined,
} )
}
/>
Expand Down
17 changes: 5 additions & 12 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,23 +216,16 @@ function block_core_navigation_build_html( $attributes, $block, $colors, $font_s
( $is_active ? ' current-menu-item' : '' ) . '"' . $style_attribute . '>' .
'<a class="wp-block-navigation-link__content"';

// Start appending HTML attributes to anchor tag.
if (
isset( $block['attrs']['url'] ) &&
isset( $block['attrs']['type'] ) &&
'URL' === $block['attrs']['type']
isset( $block['attrs']['id'] )
) {
$html .= ' href="' .
esc_url( get_permalink( $block['attrs']['id'] ) ) .
'"';
} else {
$html .= ' href="' . esc_url( $block['attrs']['url'] ) . '"';
}

if (
isset( $block['attrs']['type'] ) &&
isset( $block['attrs']['id'] ) &&
'URL' !== $block['attrs']['type']
) {
$html .= ' href="' . get_permalink( $block['attrs']['id'] ) . '"';
}

if ( isset( $block['attrs']['opensInNewTab'] ) && true === $block['attrs']['opensInNewTab'] ) {
$html .= ' target="_blank" ';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ exports[`Navigation allows a navigation menu to be created from an empty menu us

exports[`Navigation allows a navigation menu to be created using existing pages 1`] = `
"<!-- wp:navigation {\\"orientation\\":\\"horizontal\\"} -->
<!-- wp:navigation-link {\\"label\\":\\"Home\\",\\"type\\":\\"page\\",\\"id\\":1,\\"url\\":\\"https://this/is/a/test/page/home\\"} /-->
<!-- wp:navigation-link {\\"label\\":\\"Home\\",\\"id\\":1,\\"url\\":\\"https://this/is/a/test/page/home\\"} /-->
<!-- wp:navigation-link {\\"label\\":\\"About\\",\\"type\\":\\"page\\",\\"id\\":2,\\"url\\":\\"https://this/is/a/test/page/about\\"} /-->
<!-- wp:navigation-link {\\"label\\":\\"About\\",\\"id\\":2,\\"url\\":\\"https://this/is/a/test/page/about\\"} /-->
<!-- wp:navigation-link {\\"label\\":\\"Contact Us\\",\\"type\\":\\"page\\",\\"id\\":3,\\"url\\":\\"https://this/is/a/test/page/contact\\"} /-->
<!-- wp:navigation-link {\\"label\\":\\"Contact Us\\",\\"id\\":3,\\"url\\":\\"https://this/is/a/test/page/contact\\"} /-->
<!-- /wp:navigation -->"
`;

exports[`Navigation allows pages to be created from the navigation block and their links added to menu 1`] = `
"<!-- wp:navigation {\\"orientation\\":\\"horizontal\\"} -->
<!-- wp:navigation-link {\\"label\\":\\"A really long page name that will not exist\\",\\"type\\":\\"page\\",\\"id\\":1,\\"url\\":\\"https://this/is/a/test/create/page/my-new-page\\"} /-->
<!-- wp:navigation-link {\\"label\\":\\"A really long page name that will not exist\\",\\"id\\":1,\\"url\\":\\"https://this/is/a/test/create/page/my-new-page\\"} /-->
<!-- /wp:navigation -->"
`;

0 comments on commit 20558b6

Please sign in to comment.