-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FSE: Add entity editor to post content block (#22473)
Allows the user to view and edit the content of a post content block. The post content block will use whatever post ID / post type is set via block context.
- Loading branch information
1 parent
c731a88
commit 14da138
Showing
4 changed files
with
64 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "core/post-content", | ||
"category": "layout", | ||
"context": [ "postId" ] | ||
"context": [ "postId", "postType" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
export default function PostContentEdit() { | ||
return ( | ||
<p> | ||
{ | ||
'Welcome to WordPress and the wonderful world of blocks. This content represents how a post would look when editing block templates.' | ||
} | ||
</p> | ||
); | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import PostContentInnerBlocks from './inner-blocks'; | ||
|
||
export default function PostContentEdit( { context: { postId, postType } } ) { | ||
if ( postId && postType ) { | ||
return ( | ||
<PostContentInnerBlocks postType={ postType } postId={ postId } /> | ||
); | ||
} | ||
return <p>{ __( 'This is a placeholder for post content.' ) }</p>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useEntityBlockEditor } from '@wordpress/core-data'; | ||
import { InnerBlocks } from '@wordpress/block-editor'; | ||
|
||
export default function PostContentInnerBlocks( { postType, postId } ) { | ||
const [ blocks, onInput, onChange ] = useEntityBlockEditor( | ||
'postType', | ||
postType, | ||
{ id: postId } | ||
); | ||
return ( | ||
<InnerBlocks | ||
value={ blocks } | ||
onInput={ onInput } | ||
onChange={ onChange } | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters