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

Subscriptions: allow block in the navigation block #37439

Merged
merged 3 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
@@ -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;
} );
Loading