Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ public function get_item_schema() {
'context' => array( 'mobile' ),
),

'__experimentalBlockInspectorTabs' => array(
'description' => __( 'Block inspector tab display overrides.', 'gutenberg' ),
'type' => 'object',
'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
),

'alignWide' => array(
'description' => __( 'Enable/Disable Wide/Full Alignments.', 'gutenberg' ),
'type' => 'boolean',
Expand Down
27 changes: 23 additions & 4 deletions packages/block-editor/src/components/block-inspector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ function getContentBlocks( blocks, isContentBlock ) {
return result;
}

function getShowTabs( blockName, tabSettings = {} ) {
if ( tabSettings[ blockName ] !== undefined ) {
return tabSettings[ blockName ];
}

if ( tabSettings.default !== undefined ) {
return tabSettings.default;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

So at the moment you can set default: false and something like 'core/paragraph': true to enable tabs only on one block. Or default: true and 'core/paragraph': false to disable only one block.

That's pretty flexible, and honors the individual tab setting, which is nice.

The other option might be having 'default' as a separate setting entirely instead of a property, but I don't really have a strong preference either way. I wonder if anyone has ever made a block with the name 'default', as that may cause an issue. It would be going against the block naming guidelines, which recommend namespaced block names (my-plugin/default), so probably not something to worry about.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I'll be happy to trial the alternative if others have stronger opinions or different thoughts.


return window?.__experimentalEnableBlockInspectorTabs;
}

function BlockNavigationButton( { blockTypes, block, selectedBlock } ) {
const { selectBlock } = useDispatch( blockEditorStore );
const blockType = blockTypes.find( ( { name } ) => name === block.name );
Expand Down Expand Up @@ -140,26 +152,30 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => {
selectedBlockClientId,
blockType,
topLevelLockedBlock,
tabSettings,
} = useSelect( ( select ) => {
const {
getSelectedBlockClientId,
getSelectedBlockCount,
getBlockName,
__unstableGetContentLockingParent,
getTemplateLock,
getSettings,
} = select( blockEditorStore );

const _selectedBlockClientId = getSelectedBlockClientId();
const _selectedBlockName =
_selectedBlockClientId && getBlockName( _selectedBlockClientId );
const _blockType =
_selectedBlockName && getBlockType( _selectedBlockName );
const _tabSettings = getSettings().__experimentalBlockInspectorTabs;

return {
count: getSelectedBlockCount(),
selectedBlockClientId: _selectedBlockClientId,
selectedBlockName: _selectedBlockName,
blockType: _blockType,
tabSettings: _tabSettings,
topLevelLockedBlock:
__unstableGetContentLockingParent( _selectedBlockClientId ) ||
( getTemplateLock( _selectedBlockClientId ) === 'contentOnly'
Expand All @@ -170,8 +186,7 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => {

const availableTabs = useInspectorControlsTabs( blockType?.name );
const showTabs =
window?.__experimentalEnableBlockInspectorTabs &&
availableTabs.length > 1;
availableTabs.length > 1 && getShowTabs( blockType?.name, tabSettings );

if ( count > 1 ) {
return (
Expand Down Expand Up @@ -242,10 +257,14 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => {
};

const BlockInspectorSingleBlock = ( { clientId, blockName } ) => {
const tabSettings = useSelect( ( select ) => {
return select( blockEditorStore ).getSettings()
.__experimentalBlockInspectorTabs;
}, [] );

const availableTabs = useInspectorControlsTabs( blockName );
const showTabs =
window?.__experimentalEnableBlockInspectorTabs &&
availableTabs.length > 1;
availableTabs.length > 1 && getShowTabs( blockName, tabSettings );

const hasBlockStyles = useSelect(
( select ) => {
Expand Down
23 changes: 23 additions & 0 deletions packages/block-library/src/navigation-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,26 @@ function register_block_core_navigation_link() {
);
}
add_action( 'init', 'register_block_core_navigation_link' );

/**
* Disables the display of tabs for the Navigation Link block.
*
* @param array $settings Default editor settings.
* @return array Filtered editor settings.
*/
function gutenberg_disable_tabs_for_navigation_link_block( $settings ) {
$current_tab_settings = _wp_array_get(
$settings,
array( '__experimentalBlockInspectorTabs' ),
array()
);

$settings['__experimentalBlockInspectorTabs'] = array_merge(
$current_tab_settings,
array( 'core/navigation-link' => false )
);

return $settings;
}

add_filter( 'block_editor_settings_all', 'gutenberg_disable_tabs_for_navigation_link_block' );
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ function useBlockEditorSettings( settings, hasTemplate ) {
Object.entries( settings ).filter( ( [ key ] ) =>
[
'__experimentalBlockDirectory',
'__experimentalBlockInspectorTabs',
'__experimentalDiscussionSettings',
'__experimentalFeatures',
'__experimentalPreferredStyleVariations',
Expand Down