diff --git a/packages/block-library/src/post-excerpt/block.json b/packages/block-library/src/post-excerpt/block.json
index c94a5f8d2175fa..392c9cf20e5b0a 100644
--- a/packages/block-library/src/post-excerpt/block.json
+++ b/packages/block-library/src/post-excerpt/block.json
@@ -2,6 +2,9 @@
"name": "core/post-excerpt",
"category": "design",
"attributes": {
+ "align": {
+ "type": "string"
+ },
"wordCount": {
"type": "number",
"default": 55
@@ -15,9 +18,16 @@
}
},
"usesContext": [
- "postId"
+ "postId",
+ "postType"
],
"supports": {
- "html": false
+ "html": false,
+ "__experimentalFontSize": true,
+ "__experimentalColor": {
+ "gradients": true,
+ "linkColor": true
+ },
+ "__experimentalLineHeight": true
}
}
diff --git a/packages/block-library/src/post-excerpt/edit.js b/packages/block-library/src/post-excerpt/edit.js
index 49a370c488b628..8877297b20bd44 100644
--- a/packages/block-library/src/post-excerpt/edit.js
+++ b/packages/block-library/src/post-excerpt/edit.js
@@ -1,18 +1,32 @@
+/**
+ * External dependencies
+ */
+import classnames from 'classnames';
+
/**
* WordPress dependencies
*/
-import { useEntityProp, useEntityId } from '@wordpress/core-data';
+import { useEntityProp } from '@wordpress/core-data';
import { useMemo } from '@wordpress/element';
-import { InspectorControls, RichText } from '@wordpress/block-editor';
+import {
+ AlignmentToolbar,
+ BlockControls,
+ InspectorControls,
+ RichText,
+ Warning,
+} from '@wordpress/block-editor';
import { PanelBody, RangeControl, ToggleControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
-function usePostContentExcerpt( wordCount ) {
- const [ , , { raw: rawPostContent } ] = useEntityProp(
+function usePostContentExcerpt( wordCount, postId, postType ) {
+ // Don't destrcuture items from content here, it can be undefined.
+ const [ , , content ] = useEntityProp(
'postType',
- 'post',
- 'content'
+ postType,
+ 'content',
+ postId
);
+ const rawPostContent = content?.raw;
return useMemo( () => {
if ( ! rawPostContent ) {
return '';
@@ -26,18 +40,32 @@ function usePostContentExcerpt( wordCount ) {
}
function PostExcerptEditor( {
- attributes: { wordCount, moreText, showMoreOnNewLine },
+ attributes: { align, wordCount, moreText, showMoreOnNewLine },
setAttributes,
isSelected,
+ context: { postId, postType },
} ) {
const [ excerpt, setExcerpt ] = useEntityProp(
'postType',
- 'post',
- 'excerpt'
+ postType,
+ 'excerpt',
+ postId
+ );
+ const postContentExcerpt = usePostContentExcerpt(
+ wordCount,
+ postId,
+ postType
);
- const postContentExcerpt = usePostContentExcerpt( wordCount );
return (
<>
+
+
+
' . get_the_excerpt( $block->context['postId'] ); + $classes = 'wp-block-post-excerpt'; + if ( isset( $attributes['align'] ) ) { + $classes .= ' has-text-align-' . $attributes['align']; + } + + $output = sprintf( '
' . get_the_excerpt( $block->context['postId'] ); if ( ! isset( $attributes['showMoreOnNewLine'] ) || $attributes['showMoreOnNewLine'] ) { - $output .= '
' . '' . $more_text . '
'; + $output .= '' . '' . $more_text . '
'; } else { - $output .= ' ' . $more_text . ''; + $output .= ' ' . $more_text . '' . '