Skip to content

Commit

Permalink
Subscriptions: allow block in the navigation block (#37439)
Browse files Browse the repository at this point in the history
  • Loading branch information
simison authored May 17, 2024
1 parent 67349d4 commit 7b46749
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: enhancement

Subscription block: allow adding inside navigation block
17 changes: 15 additions & 2 deletions projects/plugins/jetpack/extensions/blocks/subscriptions/editor.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { registerJetpackPlugin } from '@automattic/jetpack-shared-extension-utils';
import { createBlock } from '@wordpress/blocks';
import { addFilter } from '@wordpress/hooks';
import { registerJetpackBlockFromMetadata } from '../../shared/register-jetpack-block';
import metadata from './block.json';
import deprecated from './deprecated';
import edit from './edit';
import SubscribePanels from './panel';

const name = metadata.name.replace( 'jetpack/', '' );
const blockName = metadata.name.replace( 'jetpack/', '' );

// Registers Subscribe block.
registerJetpackBlockFromMetadata( metadata, {
Expand Down Expand Up @@ -61,10 +62,22 @@ registerJetpackBlockFromMetadata( metadata, {
} );

// Registers slot/fill panels defined via settings.render.
registerJetpackPlugin( name, {
registerJetpackPlugin( blockName, {
render: () => (
<>
<SubscribePanels />
</>
),
} );

// Allows block to be inserted inside core navigation block
addFilter( 'blocks.registerBlockType', 'jetpack-subscriptions-nav-item', ( settings, name ) => {
if ( name === 'core/navigation' ) {
return {
...settings,
allowedBlocks: [ ...( settings.allowedBlocks ?? [] ), 'jetpack/subscriptions' ],
};
}

return settings;
} );

0 comments on commit 7b46749

Please sign in to comment.