From 954e87ea3a0348da64925841cedf2f94dceb3017 Mon Sep 17 00:00:00 2001 From: epiqueras Date: Fri, 10 Jan 2020 21:49:40 -0500 Subject: [PATCH 1/3] Block Library: Add a Post Excerpt block. --- lib/blocks.php | 1 + packages/block-library/src/index.js | 3 +- .../block-library/src/post-excerpt/block.json | 4 +++ .../block-library/src/post-excerpt/edit.js | 17 ++++++++++ .../block-library/src/post-excerpt/index.js | 18 +++++++++++ .../block-library/src/post-excerpt/index.php | 32 +++++++++++++++++++ 6 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 packages/block-library/src/post-excerpt/block.json create mode 100644 packages/block-library/src/post-excerpt/edit.js create mode 100644 packages/block-library/src/post-excerpt/index.js create mode 100644 packages/block-library/src/post-excerpt/index.php diff --git a/lib/blocks.php b/lib/blocks.php index f120d571f89b3a..4b5ac97a8cdc79 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -56,6 +56,7 @@ function gutenberg_reregister_core_block_types() { 'template-part.php' => 'core/template-part', 'post-title.php' => 'core/post-title', 'post-content.php' => 'core/post-content', + 'post-excerpt.php' => 'core/post-excerpt', ); $registry = WP_Block_Type_Registry::get_instance(); diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js index 15c200636626d1..d82868000de102 100644 --- a/packages/block-library/src/index.js +++ b/packages/block-library/src/index.js @@ -68,6 +68,7 @@ import * as siteTitle from './site-title'; import * as templatePart from './template-part'; import * as postTitle from './post-title'; import * as postContent from './post-content'; +import * as postExcerpt from './post-excerpt'; /** * Function to register an individual block. @@ -187,7 +188,7 @@ export const __experimentalRegisterExperimentalCoreBlocks = // Register Full Site Editing Blocks. ...( __experimentalEnableFullSiteEditing ? - [ siteTitle, templatePart, postTitle, postContent ] : + [ siteTitle, templatePart, postTitle, postContent, postExcerpt ] : [] ), ].forEach( registerBlock ); } : diff --git a/packages/block-library/src/post-excerpt/block.json b/packages/block-library/src/post-excerpt/block.json new file mode 100644 index 00000000000000..ef39be86f839cc --- /dev/null +++ b/packages/block-library/src/post-excerpt/block.json @@ -0,0 +1,4 @@ +{ + "name": "core/post-excerpt", + "category": "layout" +} diff --git a/packages/block-library/src/post-excerpt/edit.js b/packages/block-library/src/post-excerpt/edit.js new file mode 100644 index 00000000000000..f882c856027300 --- /dev/null +++ b/packages/block-library/src/post-excerpt/edit.js @@ -0,0 +1,17 @@ +/** + * WordPress dependencies + */ +import { useEntityProp, useEntityId } from '@wordpress/core-data'; +import { RichText } from '@wordpress/block-editor'; + +function PostExcerptDisplay() { + const [ excerpt ] = useEntityProp( 'postType', 'post', 'excerpt' ); + return ; +} + +export default function PostExcerptEdit() { + if ( ! useEntityId( 'postType', 'post' ) ) { + return 'Post Excerpt Placeholder'; + } + return ; +} diff --git a/packages/block-library/src/post-excerpt/index.js b/packages/block-library/src/post-excerpt/index.js new file mode 100644 index 00000000000000..a77e7bf47e829c --- /dev/null +++ b/packages/block-library/src/post-excerpt/index.js @@ -0,0 +1,18 @@ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; + +/** + * Internal dependencies + */ +import metadata from './block.json'; +import edit from './edit'; + +const { name } = metadata; +export { metadata, name }; + +export const settings = { + title: __( 'Post Excerpt' ), + edit, +}; diff --git a/packages/block-library/src/post-excerpt/index.php b/packages/block-library/src/post-excerpt/index.php new file mode 100644 index 00000000000000..06d1b9726468fc --- /dev/null +++ b/packages/block-library/src/post-excerpt/index.php @@ -0,0 +1,32 @@ +' . get_the_excerpt( $post ) . '

'; +} + +/** + * Registers the `core/post-excerpt` block on the server. + */ +function register_block_core_post_excerpt() { + register_block_type( + 'core/post-excerpt', + array( + 'render_callback' => 'render_block_core_post_excerpt', + ) + ); +} +add_action( 'init', 'register_block_core_post_excerpt' ); From f9a10c85fb9999756f0484c5c3ec9f73f17eff7f Mon Sep 17 00:00:00 2001 From: epiqueras Date: Mon, 13 Jan 2020 09:04:54 -0500 Subject: [PATCH 2/3] Block Library: Make Post Excerpt block editable. --- packages/block-library/src/post-excerpt/edit.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/post-excerpt/edit.js b/packages/block-library/src/post-excerpt/edit.js index f882c856027300..22bf69a583dc3a 100644 --- a/packages/block-library/src/post-excerpt/edit.js +++ b/packages/block-library/src/post-excerpt/edit.js @@ -2,11 +2,11 @@ * WordPress dependencies */ import { useEntityProp, useEntityId } from '@wordpress/core-data'; -import { RichText } from '@wordpress/block-editor'; +import { PlainText } from '@wordpress/block-editor'; function PostExcerptDisplay() { - const [ excerpt ] = useEntityProp( 'postType', 'post', 'excerpt' ); - return ; + const [ excerpt, setExcerpt ] = useEntityProp( 'postType', 'post', 'excerpt' ); + return ; } export default function PostExcerptEdit() { From f358085d221d6b40103081e9ec072e5b72377abb Mon Sep 17 00:00:00 2001 From: epiqueras <epiquerass@gmail.com> Date: Mon, 13 Jan 2020 10:54:36 -0500 Subject: [PATCH 3/3] E2E Tests: Add Post Excerpt block fixtures. --- .../fixtures/blocks/core__post-excerpt.html | 1 + .../fixtures/blocks/core__post-excerpt.json | 10 ++++++++++ .../blocks/core__post-excerpt.parsed.json | 18 ++++++++++++++++++ .../blocks/core__post-excerpt.serialized.html | 1 + 4 files changed, 30 insertions(+) create mode 100644 packages/e2e-tests/fixtures/blocks/core__post-excerpt.html create mode 100644 packages/e2e-tests/fixtures/blocks/core__post-excerpt.json create mode 100644 packages/e2e-tests/fixtures/blocks/core__post-excerpt.parsed.json create mode 100644 packages/e2e-tests/fixtures/blocks/core__post-excerpt.serialized.html diff --git a/packages/e2e-tests/fixtures/blocks/core__post-excerpt.html b/packages/e2e-tests/fixtures/blocks/core__post-excerpt.html new file mode 100644 index 00000000000000..7e9cdd6a03339c --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__post-excerpt.html @@ -0,0 +1 @@ +<!-- wp:post-excerpt /--> diff --git a/packages/e2e-tests/fixtures/blocks/core__post-excerpt.json b/packages/e2e-tests/fixtures/blocks/core__post-excerpt.json new file mode 100644 index 00000000000000..67bee1bd83f275 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__post-excerpt.json @@ -0,0 +1,10 @@ +[ + { + "clientId": "_clientId_0", + "name": "core/post-excerpt", + "isValid": true, + "attributes": {}, + "innerBlocks": [], + "originalContent": "" + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__post-excerpt.parsed.json b/packages/e2e-tests/fixtures/blocks/core__post-excerpt.parsed.json new file mode 100644 index 00000000000000..509101167e1d97 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__post-excerpt.parsed.json @@ -0,0 +1,18 @@ +[ + { + "blockName": "core/post-excerpt", + "attrs": {}, + "innerBlocks": [], + "innerHTML": "", + "innerContent": [] + }, + { + "blockName": null, + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n", + "innerContent": [ + "\n" + ] + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__post-excerpt.serialized.html b/packages/e2e-tests/fixtures/blocks/core__post-excerpt.serialized.html new file mode 100644 index 00000000000000..7e9cdd6a03339c --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__post-excerpt.serialized.html @@ -0,0 +1 @@ +<!-- wp:post-excerpt /-->