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

Add Paragraph prompt to Post Content when empty #50623

Merged
merged 5 commits into from
May 26, 2023
Merged
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
24 changes: 22 additions & 2 deletions packages/block-library/src/post-content/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import {
__experimentalUseHasRecursion as useHasRecursion,
Warning,
} from '@wordpress/block-editor';
import { useEntityProp, useEntityBlockEditor } from '@wordpress/core-data';

import {
useEntityProp,
useEntityBlockEditor,
store as coreStore,
} from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
Expand Down Expand Up @@ -45,12 +49,28 @@ function EditableContent( { context = {} } ) {
{ id: postId }
);

const entityRecord = useSelect(
( select ) => {
return select( coreStore ).getEntityRecord(
'postType',
postType,
postId
);
},
[ postType, postId ]
);

const hasInnerBlocks = !! entityRecord?.content?.raw || blocks?.length;

const initialInnerBlocks = [ [ 'core/paragraph' ] ];

const props = useInnerBlocksProps(
useBlockProps( { className: 'entry-content' } ),
{
value: blocks,
onInput,
onChange,
template: ! hasInnerBlocks ? initialInnerBlocks : undefined,
}
);
return <div { ...props } />;
Expand Down