diff --git a/lib/blocks.php b/lib/blocks.php index fd6945f23db0a..e0aa1725f6725 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -57,6 +57,7 @@ function gutenberg_reregister_core_block_types() { 'post-title.php' => 'core/post-title', 'post-content.php' => 'core/post-content', 'post-author.php' => 'core/post-author', + 'post-date.php' => 'core/post-date', 'post-excerpt.php' => 'core/post-excerpt', ); diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js index d7846790d30a8..c18b65eba6172 100644 --- a/packages/block-library/src/index.js +++ b/packages/block-library/src/index.js @@ -69,6 +69,7 @@ import * as templatePart from './template-part'; import * as postTitle from './post-title'; import * as postContent from './post-content'; import * as postAuthor from './post-author'; +import * as postDate from './post-date'; import * as postExcerpt from './post-excerpt'; /** @@ -195,6 +196,7 @@ export const __experimentalRegisterExperimentalCoreBlocks = postTitle, postContent, postAuthor, + postDate, postExcerpt, ] : [] ), diff --git a/packages/block-library/src/post-date/block.json b/packages/block-library/src/post-date/block.json new file mode 100644 index 0000000000000..3e14e60aaf3e4 --- /dev/null +++ b/packages/block-library/src/post-date/block.json @@ -0,0 +1,4 @@ +{ + "name": "core/post-date", + "category": "layout" +} diff --git a/packages/block-library/src/post-date/edit.js b/packages/block-library/src/post-date/edit.js new file mode 100644 index 0000000000000..b677d57d002b8 --- /dev/null +++ b/packages/block-library/src/post-date/edit.js @@ -0,0 +1,26 @@ +/** + * WordPress dependencies + */ +import { useEntityProp, useEntityId } from '@wordpress/core-data'; +import { __experimentalGetSettings, dateI18n } from '@wordpress/date'; +import { __ } from '@wordpress/i18n'; + +function PostDateDisplay() { + const [ date ] = useEntityProp( 'postType', 'post', 'date' ); + const settings = __experimentalGetSettings(); + + return date ? ( + + ) : ( + __( 'No Date' ) + ); +} + +export default function PostDateEdit() { + if ( ! useEntityId( 'postType', 'post' ) ) { + return 'Post Date Placeholder'; + } + return ; +} diff --git a/packages/block-library/src/post-date/index.js b/packages/block-library/src/post-date/index.js new file mode 100644 index 0000000000000..2ae69d12de74d --- /dev/null +++ b/packages/block-library/src/post-date/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 Date' ), + edit, +}; diff --git a/packages/block-library/src/post-date/index.php b/packages/block-library/src/post-date/index.php new file mode 100644 index 0000000000000..25914a0fe6255 --- /dev/null +++ b/packages/block-library/src/post-date/index.php @@ -0,0 +1,32 @@ +' . get_the_date( '', $post ) . ''; +} + +/** + * Registers the `core/post-date` block on the server. + */ +function register_block_core_post_date() { + register_block_type( + 'core/post-date', + array( + 'render_callback' => 'render_block_core_post_date', + ) + ); +} +add_action( 'init', 'register_block_core_post_date' ); diff --git a/packages/e2e-tests/fixtures/blocks/core__post-date.html b/packages/e2e-tests/fixtures/blocks/core__post-date.html new file mode 100644 index 0000000000000..56357e03f4990 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__post-date.html @@ -0,0 +1 @@ + diff --git a/packages/e2e-tests/fixtures/blocks/core__post-date.json b/packages/e2e-tests/fixtures/blocks/core__post-date.json new file mode 100644 index 0000000000000..42e12a85c4962 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__post-date.json @@ -0,0 +1,10 @@ +[ + { + "clientId": "_clientId_0", + "name": "core/post-date", + "isValid": true, + "attributes": {}, + "innerBlocks": [], + "originalContent": "" + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__post-date.parsed.json b/packages/e2e-tests/fixtures/blocks/core__post-date.parsed.json new file mode 100644 index 0000000000000..6a912b2c3214a --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__post-date.parsed.json @@ -0,0 +1,18 @@ +[ + { + "blockName": "core/post-date", + "attrs": {}, + "innerBlocks": [], + "innerHTML": "", + "innerContent": [] + }, + { + "blockName": null, + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n", + "innerContent": [ + "\n" + ] + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__post-date.serialized.html b/packages/e2e-tests/fixtures/blocks/core__post-date.serialized.html new file mode 100644 index 0000000000000..56357e03f4990 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__post-date.serialized.html @@ -0,0 +1 @@ +