diff --git a/packages/block-library/src/post-tags/block.json b/packages/block-library/src/post-tags/block.json
index b3b0e6772c4e9..cf33f797bb687 100644
--- a/packages/block-library/src/post-tags/block.json
+++ b/packages/block-library/src/post-tags/block.json
@@ -1,10 +1,9 @@
{
"name": "core/post-tags",
"category": "design",
- "usesContext": [
- "postId"
- ],
+ "usesContext": [ "postId", "postType" ],
"supports": {
- "html": false
+ "html": false,
+ "lightBlockWrapper": true
}
}
diff --git a/packages/block-library/src/post-tags/edit.js b/packages/block-library/src/post-tags/edit.js
index 38787e46c5db1..faa14e437da4a 100644
--- a/packages/block-library/src/post-tags/edit.js
+++ b/packages/block-library/src/post-tags/edit.js
@@ -1,17 +1,24 @@
/**
* WordPress dependencies
*/
-import { useEntityProp, useEntityId } from '@wordpress/core-data';
+import { useEntityProp } from '@wordpress/core-data';
+import { Warning, __experimentalBlock as Block } from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
-function PostTagsDisplay() {
- const [ tags ] = useEntityProp( 'postType', 'post', 'tags' );
+export default function PostTagsEdit( { context } ) {
+ const [ tags ] = useEntityProp(
+ 'postType',
+ context.postType,
+ 'tags',
+ context.postId
+ );
const tagLinks = useSelect(
( select ) => {
const { getEntityRecord } = select( 'core' );
let loaded = true;
- const links = tags.map( ( tagId ) => {
+
+ const links = tags?.map( ( tagId ) => {
const tag = getEntityRecord( 'taxonomy', 'post_tag', tagId );
if ( ! tag ) {
return ( loaded = false );
@@ -22,21 +29,41 @@ function PostTagsDisplay() {
);
} );
+
return loaded && links;
},
[ tags ]
);
- return (
+
+ let display =
tagLinks &&
( tagLinks.length === 0
? __( 'No tags.' )
- : tagLinks.reduce( ( prev, curr ) => [ prev, ' | ', curr ] ) )
- );
-}
+ : tagLinks.reduce( ( prev, curr ) => [ prev, ' | ', curr ] ) );
-export default function PostTagsEdit() {
- if ( ! useEntityId( 'postType', 'post' ) ) {
- return __( 'Post Tags' );
+ if ( ! context.postType || ! context.postId ) {
+ display = (
+