-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Footnotes: disable based on post type #52934
Changes from all commits
ecc4349
d275257
216f5a6
185c7b3
3528458
75330ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,14 +12,18 @@ import { insertObject } from '@wordpress/rich-text'; | |
import { | ||
RichTextToolbarButton, | ||
store as blockEditorStore, | ||
privateApis, | ||
} from '@wordpress/block-editor'; | ||
import { useSelect, useDispatch, useRegistry } from '@wordpress/data'; | ||
import { createBlock } from '@wordpress/blocks'; | ||
import { createBlock, store as blocksStore } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { name } from './block.json'; | ||
import { unlock } from '../lock-unlock'; | ||
|
||
const { usesContextKey } = unlock( privateApis ); | ||
|
||
export const formatName = 'core/footnote'; | ||
export const format = { | ||
|
@@ -30,17 +34,34 @@ export const format = { | |
'data-fn': 'data-fn', | ||
}, | ||
contentEditable: false, | ||
edit: function Edit( { value, onChange, isObjectActive } ) { | ||
[ usesContextKey ]: [ 'postType' ], | ||
edit: function Edit( { | ||
value, | ||
onChange, | ||
isObjectActive, | ||
context: { postType }, | ||
} ) { | ||
const registry = useRegistry(); | ||
const { | ||
getSelectedBlockClientId, | ||
getBlockRootClientId, | ||
getBlockName, | ||
getBlocks, | ||
} = useSelect( blockEditorStore ); | ||
const footnotesBlockType = useSelect( ( select ) => | ||
select( blocksStore ).getBlockType( name ) | ||
); | ||
const { selectionChange, insertBlock } = | ||
useDispatch( blockEditorStore ); | ||
|
||
if ( ! footnotesBlockType ) { | ||
return null; | ||
} | ||
|
||
if ( postType !== 'post' && postType !== 'page' ) { | ||
return null; | ||
} | ||
Comment on lines
+61
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note for follow-up: We should check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if we can do that. What If some block disables footnotes to be inserted as inner blocks? That doesn't mean footnote anchors can't be inserted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So maybe what we should check here is well is just if footnotes is registered at all? But I guess the preference doesn't unregister it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll need to check if the footnotes block is disabled; it doesn't have to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like that is in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a registration check in 185c7b3, but that doesn't fix the preferences problem. Not sure if we should depend on the edit post package. Maybe the footnotes block doesn't belong in the block library package. Or is it fine to add the dependency? |
||
|
||
function onClick() { | ||
registry.batch( () => { | ||
let id; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Props @mcsf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄