diff --git a/packages/block-library/src/post-comment-date/block.json b/packages/block-library/src/post-comment-date/block.json index 246711340a60e..c162fbf901ff4 100644 --- a/packages/block-library/src/post-comment-date/block.json +++ b/packages/block-library/src/post-comment-date/block.json @@ -9,10 +9,27 @@ "attributes": { "format": { "type": "string" + }, + "isLink": { + "type": "boolean", + "default": false } }, "usesContext": [ "commentId" ], "supports": { - "html": false + "html": false, + "color": { + "gradients": true, + "link": true + }, + "typography": { + "fontSize": true, + "lineHeight": true, + "__experimentalFontFamily": true, + "__experimentalFontWeight": true, + "__experimentalFontStyle": true, + "__experimentalTextTransform": true, + "__experimentalLetterSpacing": true + } } } diff --git a/packages/block-library/src/post-comment-date/edit.js b/packages/block-library/src/post-comment-date/edit.js index 6a1a2d765d8c8..fb1c311fab1b5 100644 --- a/packages/block-library/src/post-comment-date/edit.js +++ b/packages/block-library/src/post-comment-date/edit.js @@ -4,11 +4,15 @@ import { useEntityProp } from '@wordpress/core-data'; import { __experimentalGetSettings, dateI18n } from '@wordpress/date'; import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; -import { PanelBody, CustomSelectControl } from '@wordpress/components'; +import { + PanelBody, + CustomSelectControl, + ToggleControl, +} from '@wordpress/components'; import { __ } from '@wordpress/i18n'; export default function Edit( { attributes, context, setAttributes } ) { - const { className, format } = attributes; + const { className, format, isLink } = attributes; const { commentId } = context; const settings = __experimentalGetSettings(); @@ -24,6 +28,23 @@ export default function Edit( { attributes, context, setAttributes } ) { const resolvedFormat = format || siteDateFormat || settings.formats.date; const blockProps = useBlockProps( { className } ); + let commentDate = ( + + ); + + if ( isLink ) { + commentDate = ( + event.preventDefault() } + > + { commentDate } + + ); + } + return ( <> @@ -42,13 +63,15 @@ export default function Edit( { attributes, context, setAttributes } ) { ) } /> + + setAttributes( { isLink: ! isLink } ) } + checked={ isLink } + /> + - -
- -
+
{ commentDate }
); } diff --git a/packages/block-library/src/post-comment-date/index.php b/packages/block-library/src/post-comment-date/index.php index f46529b55e295..1a52e08fc3df8 100644 --- a/packages/block-library/src/post-comment-date/index.php +++ b/packages/block-library/src/post-comment-date/index.php @@ -19,14 +19,21 @@ function render_block_core_post_comment_date( $attributes, $content, $block ) { } $wrapper_attributes = get_block_wrapper_attributes(); + $formatted_date = get_comment_date( + isset( $attributes['format'] ) ? $attributes['format'] : '', + $block->context['commentId'] + ); + $link = get_comment_link( $block->context['commentId'] ); + + if ( ! empty( $attributes['isLink'] ) ) { + $formatted_date = sprintf( '%2s', $link, $formatted_date ); + } + return sprintf( '
', $wrapper_attributes, get_comment_date( 'c', $block->context['commentId'] ), - get_comment_date( - isset( $attributes['format'] ) ? $attributes['format'] : '', - $block->context['commentId'] - ) + $formatted_date ); } diff --git a/test/integration/fixtures/blocks/core__post-comment-date.json b/test/integration/fixtures/blocks/core__post-comment-date.json index 4abcc999f9627..3bce3436fe805 100644 --- a/test/integration/fixtures/blocks/core__post-comment-date.json +++ b/test/integration/fixtures/blocks/core__post-comment-date.json @@ -3,7 +3,9 @@ "clientId": "_clientId_0", "name": "core/post-comment-date", "isValid": true, - "attributes": {}, + "attributes": { + "isLink": false + }, "innerBlocks": [], "originalContent": "" }