From 48536e79eb0e1681c80704e899e767aebb30ce1d Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Sat, 28 Sep 2019 18:54:27 +0300 Subject: [PATCH] default state for the menu --- .../block-library/src/navigation-menu/edit.js | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation-menu/edit.js b/packages/block-library/src/navigation-menu/edit.js index 67025c2a2d04b8..06db871bcbc445 100644 --- a/packages/block-library/src/navigation-menu/edit.js +++ b/packages/block-library/src/navigation-menu/edit.js @@ -9,6 +9,7 @@ import { InspectorControls, BlockControls, } from '@wordpress/block-editor'; +import { withSelect } from '@wordpress/data'; import { CheckboxControl, PanelBody, @@ -25,8 +26,17 @@ function NavigationMenu( { attributes, setAttributes, clientId, + pages, } ) { const { navigatorToolbarButton, navigatorModal } = useBlockNavigator( clientId ); + let defaultMenuItems = false; + if ( pages ) { + defaultMenuItems = pages.map( ( page ) => { + return [ 'core/navigation-menu-item', + { label: page.title.rendered, destination: page.permalink_template }, + ]; + } ); + } return ( @@ -52,6 +62,7 @@ function NavigationMenu( {
@@ -60,4 +71,13 @@ function NavigationMenu( { ); } -export default NavigationMenu; +export default withSelect( ( select ) => { + const { getEntityRecords } = select( 'core' ); + const filterDefaultPages = { + parent: 0, + }; + return { + pages: getEntityRecords( 'postType', 'page', filterDefaultPages ), + }; +} )( NavigationMenu ); +