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

Navigation: Surface menu name in the List View next to the Navigation block #68446

Merged
Merged
23 changes: 22 additions & 1 deletion packages/block-library/src/navigation/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { navigation as icon } from '@wordpress/icons';
import { select } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand Down Expand Up @@ -52,6 +54,25 @@ export const settings = {
},
edit,
save,
__experimentalLabel: ( { ref } ) => {
if ( ! ref ) {
return __( 'Navigation' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The block title may have changed. Example code:

function change_navigation_block_name( $args, $block_type ) {
	if ( 'core/navigation' !== $block_type ) {
		return $args;
	}
	$args['title'] = __( 'My Navigation!' );
	return $args;
}
add_filter( "register_block_type_args", "change_navigation_block_name", 10, 2 );

Should this possibility be considered?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can return undefined here. This will signal the block editor to display the block's default title.

See the Template Part block for a similar example:

if ( ! slug ) {
return;
}

}

const navigation = select( coreStore ).getEntityRecord(
'postType',
'wp_navigation',
ref
);

return navigation?.title?.rendered
? sprintf(
/* translators: %s: menu title */
__( 'Navigation (%s)' ),
fabiankaegy marked this conversation as resolved.
Show resolved Hide resolved
navigation.title.rendered
fabiankaegy marked this conversation as resolved.
Show resolved Hide resolved
)
: __( 'Navigation' );
},
deprecated,
};

Expand Down
Loading