diff --git a/packages/block-library/src/post-date/block.json b/packages/block-library/src/post-date/block.json index b52aa056853f3d..eb8dee14f95d21 100644 --- a/packages/block-library/src/post-date/block.json +++ b/packages/block-library/src/post-date/block.json @@ -2,14 +2,24 @@ "name": "core/post-date", "category": "design", "attributes": { + "align": { + "type": "string" + }, "format": { "type": "string" } }, "usesContext": [ - "postId" + "postId", + "postType" ], "supports": { - "html": false + "html": false, + "lightBlockWrapper": true, + "__experimentalColor": { + "gradients": true + }, + "__experimentalFontSize": true, + "__experimentalLineHeight": true } } diff --git a/packages/block-library/src/post-date/edit.js b/packages/block-library/src/post-date/edit.js index da53a899925bde..34c0340495fecf 100644 --- a/packages/block-library/src/post-date/edit.js +++ b/packages/block-library/src/post-date/edit.js @@ -1,10 +1,20 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; + /** * WordPress dependencies */ -import { useEntityProp, useEntityId } from '@wordpress/core-data'; +import { useEntityProp } from '@wordpress/core-data'; import { useState } from '@wordpress/element'; import { __experimentalGetSettings, dateI18n } from '@wordpress/date'; -import { BlockControls, InspectorControls } from '@wordpress/block-editor'; +import { + AlignmentToolbar, + BlockControls, + InspectorControls, + __experimentalBlock as Block, +} from '@wordpress/block-editor'; import { ToolbarGroup, ToolbarButton, @@ -15,9 +25,17 @@ import { } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; -function PostDateEditor( { format, setAttributes } ) { +export default function PostDateEdit( { attributes, context, setAttributes } ) { + const { align, format } = attributes; + const { postId, postType } = context; + const [ siteFormat ] = useEntityProp( 'root', 'site', 'date_format' ); - const [ date, setDate ] = useEntityProp( 'postType', 'post', 'date' ); + const [ date, setDate ] = useEntityProp( + 'postType', + postType, + 'date', + postId + ); const [ isPickerOpen, setIsPickerOpen ] = useState( false ); const settings = __experimentalGetSettings(); // To know if the current time format is a 12 hour time, look for "a". @@ -37,31 +55,32 @@ function PostDateEditor( { format, setAttributes } ) { } ) ); const resolvedFormat = format || siteFormat || settings.formats.date; - return date ? ( - - ) : ( - __( 'No Date' ) - ); -} -export default function PostDateEdit( { - attributes: { format }, - setAttributes, -} ) { - if ( ! useEntityId( 'postType', 'post' ) ) { - return

{ __( 'Jan 1st, 1440' ) }

; - } - return ; + + { date && ( + + ) } + { ! date && __( 'No Date' ) } + + + ); } diff --git a/packages/block-library/src/post-date/index.php b/packages/block-library/src/post-date/index.php index cd6fe0ecb23be6..0412b460bff4e7 100644 --- a/packages/block-library/src/post-date/index.php +++ b/packages/block-library/src/post-date/index.php @@ -18,10 +18,14 @@ function render_block_core_post_date( $attributes, $content, $block ) { return ''; } - return ''; + $align_class_name = empty( $attributes['align'] ) ? '' : ' ' . "has-text-align-{$attributes['align']}"; + + return sprintf( + '
', + 'wp-block-post-date' . esc_attr( $align_class_name ), + get_the_date( 'c', $block->context['postId'] ), + get_the_date( isset( $attributes['format'] ) ? $attributes['format'] : '', $block->context['postId'] ) + ); } /**