Skip to content

Commit

Permalink
default state for the menu
Browse files Browse the repository at this point in the history
  • Loading branch information
draganescu committed Sep 28, 2019
1 parent c8479f0 commit 48536e7
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/block-library/src/navigation-menu/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
InspectorControls,
BlockControls,
} from '@wordpress/block-editor';
import { withSelect } from '@wordpress/data';
import {
CheckboxControl,
PanelBody,
Expand All @@ -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 (
<Fragment>
Expand All @@ -52,6 +62,7 @@ function NavigationMenu( {
</InspectorControls>
<div className="wp-block-navigation-menu">
<InnerBlocks
template={ defaultMenuItems ? defaultMenuItems : null }
allowedBlocks={ [ 'core/navigation-menu-item' ] }
renderAppender={ InnerBlocks.ButtonBlockAppender }
/>
Expand All @@ -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 );

0 comments on commit 48536e7

Please sign in to comment.