From 848bb3ab7d1ef599d21a3078d383135230114f5e Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Mon, 11 Oct 2021 16:13:26 +0200 Subject: [PATCH 1/8] Update post comment author icon --- .../src/post-comment-author/index.js | 2 +- packages/icons/src/index.js | 1 + .../icons/src/library/post-comments-author.js | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 packages/icons/src/library/post-comments-author.js diff --git a/packages/block-library/src/post-comment-author/index.js b/packages/block-library/src/post-comment-author/index.js index 68fb2c2f737c2..a203d8feb29b9 100644 --- a/packages/block-library/src/post-comment-author/index.js +++ b/packages/block-library/src/post-comment-author/index.js @@ -7,7 +7,7 @@ import edit from './edit'; /** * WordPress dependencies */ -import { postAuthor as icon } from '@wordpress/icons'; +import { postCommentsAuthor as icon } from '@wordpress/icons'; const { name } = metadata; export { metadata, name }; diff --git a/packages/icons/src/index.js b/packages/icons/src/index.js index 15ece72ab4c7e..824020256cb15 100644 --- a/packages/icons/src/index.js +++ b/packages/icons/src/index.js @@ -153,6 +153,7 @@ export { default as postContent } from './library/post-content'; export { default as postComments } from './library/post-comments'; export { default as postCommentsCount } from './library/post-comments-count'; export { default as postCommentsForm } from './library/post-comments-form'; +export { default as postCommentsAuthor } from './library/post-comments-author'; export { default as postDate } from './library/post-date'; export { default as postExcerpt } from './library/post-excerpt'; export { default as postFeaturedImage } from './library/post-featured-image'; diff --git a/packages/icons/src/library/post-comments-author.js b/packages/icons/src/library/post-comments-author.js new file mode 100644 index 0000000000000..4e8d72e5c5a62 --- /dev/null +++ b/packages/icons/src/library/post-comments-author.js @@ -0,0 +1,22 @@ +/** + * WordPress dependencies + */ +import { SVG, Path, Circle } from '@wordpress/primitives'; + +const postCommentsAuthor = ( + + + + + +); + +export default postCommentsAuthor; From 3c0e791a6cfa7670cdb5fa359f2da6fcc0352919 Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Wed, 13 Oct 2021 16:13:51 +0200 Subject: [PATCH 2/8] Update post comment author with new options --- .../src/post-comment-author/block.json | 25 +++++++++- .../src/post-comment-author/edit.js | 47 +++++++++++++++---- .../src/post-comment-author/index.php | 8 +++- .../blocks/core__post-comment-author.json | 5 +- 4 files changed, 74 insertions(+), 11 deletions(-) diff --git a/packages/block-library/src/post-comment-author/block.json b/packages/block-library/src/post-comment-author/block.json index c3a2231cc5d10..7faa0b7ad9f2a 100644 --- a/packages/block-library/src/post-comment-author/block.json +++ b/packages/block-library/src/post-comment-author/block.json @@ -6,8 +6,31 @@ "parent": [ "core/post-comment" ], "description": "Post comment author.", "textdomain": "default", + "attributes": { + "isLink": { + "type": "boolean", + "default": false + }, + "linkTarget": { + "type": "string", + "default": "_self" + } + }, "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-author/edit.js b/packages/block-library/src/post-comment-author/edit.js index d63d1cf5a958f..c4c8e350d4447 100644 --- a/packages/block-library/src/post-comment-author/edit.js +++ b/packages/block-library/src/post-comment-author/edit.js @@ -3,12 +3,14 @@ */ import { __ } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; -import { useBlockProps } from '@wordpress/block-editor'; +import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; import { store as coreStore } from '@wordpress/core-data'; +import { PanelBody, ToggleControl } from '@wordpress/components'; -export default function Edit( { attributes, context } ) { - const { className } = attributes; +export default function Edit( { attributes, context, setAttributes } ) { + const { className, isLink, linkTarget } = attributes; const { commentId } = context; + const blockProps = useBlockProps( { className } ); const displayName = useSelect( ( select ) => { @@ -21,15 +23,44 @@ export default function Edit( { attributes, context } ) { const user = getEntityRecord( 'root', 'user', comment.author ); return user?.name ?? __( 'Anonymous' ); } - + if ( isLink ) { + return ( + event.preventDefault() } + > + { authorName } + + ); + } return authorName ?? ''; }, - [ commentId ] + [ commentId, isLink ] ); return ( -
-

{ displayName }

-
+ <> + + + setAttributes( { isLink: ! isLink } ) } + checked={ isLink } + /> + { isLink && ( + + setAttributes( { + linkTarget: value ? '_blank' : '_self', + } ) + } + checked={ linkTarget === '_blank' } + /> + ) } + + +
{ displayName }
+ ); } diff --git a/packages/block-library/src/post-comment-author/index.php b/packages/block-library/src/post-comment-author/index.php index 9cad587d3d447..06016567d8d52 100644 --- a/packages/block-library/src/post-comment-author/index.php +++ b/packages/block-library/src/post-comment-author/index.php @@ -19,11 +19,17 @@ function render_block_core_post_comment_author( $attributes, $content, $block ) } $wrapper_attributes = get_block_wrapper_attributes(); + $comment_author = get_comment_author( $block->context['commentId'] ); + $link = get_comment_author_url( $block->context['commentId'] ); + + if ( ! empty( $attributes['isLink'] ) && ! empty( $attributes['linkTarget'] ) ) { + $comment_author = sprintf( '%3s', $link, $attributes['linkTarget'], $comment_author ); + } return sprintf( '
%2$s
', $wrapper_attributes, - get_comment_author( $block->context['commentId'] ) + $comment_author, ); } diff --git a/test/integration/fixtures/blocks/core__post-comment-author.json b/test/integration/fixtures/blocks/core__post-comment-author.json index 4e476b9020912..1418da92d5db6 100644 --- a/test/integration/fixtures/blocks/core__post-comment-author.json +++ b/test/integration/fixtures/blocks/core__post-comment-author.json @@ -3,7 +3,10 @@ "clientId": "_clientId_0", "name": "core/post-comment-author", "isValid": true, - "attributes": {}, + "attributes": { + "isLink": false, + "linkTarget": "_self" + }, "innerBlocks": [], "originalContent": "" } From 95a0735d4c8b248955e6ca9c3f400479d321a89c Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Wed, 13 Oct 2021 16:38:59 +0200 Subject: [PATCH 3/8] Refactor to move the link wrapper outside the select function --- .../src/post-comment-author/edit.js | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/block-library/src/post-comment-author/edit.js b/packages/block-library/src/post-comment-author/edit.js index c4c8e350d4447..f49438cf36210 100644 --- a/packages/block-library/src/post-comment-author/edit.js +++ b/packages/block-library/src/post-comment-author/edit.js @@ -23,19 +23,20 @@ export default function Edit( { attributes, context, setAttributes } ) { const user = getEntityRecord( 'root', 'user', comment.author ); return user?.name ?? __( 'Anonymous' ); } - if ( isLink ) { - return ( - event.preventDefault() } - > - { authorName } - - ); - } return authorName ?? ''; }, - [ commentId, isLink ] + [ commentId ] + ); + + const displayAuthor = isLink ? ( + event.preventDefault() } + > + { displayName } + + ) : ( + displayName ); return ( @@ -60,7 +61,7 @@ export default function Edit( { attributes, context, setAttributes } ) { ) } -
{ displayName }
+
{ displayAuthor }
); } From e1824c7fe45f2ad26804b9e8c9f2629f41d2fbfe Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Wed, 13 Oct 2021 17:10:58 +0200 Subject: [PATCH 4/8] Fix linter comma trailing on php --- packages/block-library/src/post-comment-author/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/post-comment-author/index.php b/packages/block-library/src/post-comment-author/index.php index 06016567d8d52..12e3c331cb3ea 100644 --- a/packages/block-library/src/post-comment-author/index.php +++ b/packages/block-library/src/post-comment-author/index.php @@ -29,7 +29,7 @@ function render_block_core_post_comment_author( $attributes, $content, $block ) return sprintf( '
%2$s
', $wrapper_attributes, - $comment_author, + $comment_author ); } From 4d53bf0d98a4b7a741bd3559e68fa126ed3bc560 Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Thu, 14 Oct 2021 10:34:37 +0200 Subject: [PATCH 5/8] Fixed some comments --- packages/block-library/src/post-comment-author/edit.js | 10 ++++++++++ .../block-library/src/post-comment-author/index.php | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/post-comment-author/edit.js b/packages/block-library/src/post-comment-author/edit.js index f49438cf36210..97a92b9fe9bd4 100644 --- a/packages/block-library/src/post-comment-author/edit.js +++ b/packages/block-library/src/post-comment-author/edit.js @@ -7,6 +7,16 @@ import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; import { store as coreStore } from '@wordpress/core-data'; import { PanelBody, ToggleControl } from '@wordpress/components'; +/** + * Renders the `core/post-comment-author` block on the editor. + * + * @param {Object} props React props. + * @param {Object} props.setAttributes Callback for updating block attributes. + * @param {Object} props.attributes Block attributes. + * @param {Object} props.context Inherited context. + * + * @return {JSX.Element} React element. + */ export default function Edit( { attributes, context, setAttributes } ) { const { className, isLink, linkTarget } = attributes; const { commentId } = context; diff --git a/packages/block-library/src/post-comment-author/index.php b/packages/block-library/src/post-comment-author/index.php index 12e3c331cb3ea..430b0c8d4b254 100644 --- a/packages/block-library/src/post-comment-author/index.php +++ b/packages/block-library/src/post-comment-author/index.php @@ -11,7 +11,7 @@ * @param array $attributes Block attributes. * @param string $content Block default content. * @param WP_Block $block Block instance. - * @return string Return the post comment's content. + * @return string Return the post comment's author. */ function render_block_core_post_comment_author( $attributes, $content, $block ) { if ( ! isset( $block->context['commentId'] ) ) { From f9c26e47ebac31f85271ade8686eb00995874655 Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Thu, 14 Oct 2021 14:16:50 +0200 Subject: [PATCH 6/8] Add p tag inside, renamed icon --- packages/block-library/src/post-comment-author/edit.js | 2 +- packages/block-library/src/post-comment-author/index.js | 2 +- packages/icons/src/index.js | 2 +- .../library/{post-comments-author.js => comment-author.js} | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) rename packages/icons/src/library/{post-comments-author.js => comment-author.js} (90%) diff --git a/packages/block-library/src/post-comment-author/edit.js b/packages/block-library/src/post-comment-author/edit.js index 97a92b9fe9bd4..ed4a3f4733ae5 100644 --- a/packages/block-library/src/post-comment-author/edit.js +++ b/packages/block-library/src/post-comment-author/edit.js @@ -46,7 +46,7 @@ export default function Edit( { attributes, context, setAttributes } ) { { displayName } ) : ( - displayName +

{ displayName }

); return ( diff --git a/packages/block-library/src/post-comment-author/index.js b/packages/block-library/src/post-comment-author/index.js index a203d8feb29b9..e6779fa3ec22a 100644 --- a/packages/block-library/src/post-comment-author/index.js +++ b/packages/block-library/src/post-comment-author/index.js @@ -7,7 +7,7 @@ import edit from './edit'; /** * WordPress dependencies */ -import { postCommentsAuthor as icon } from '@wordpress/icons'; +import { commentAuthor as icon } from '@wordpress/icons'; const { name } = metadata; export { metadata, name }; diff --git a/packages/icons/src/index.js b/packages/icons/src/index.js index 824020256cb15..360f93e673cf1 100644 --- a/packages/icons/src/index.js +++ b/packages/icons/src/index.js @@ -49,6 +49,7 @@ export { default as color } from './library/color'; export { default as column } from './library/column'; export { default as columns } from './library/columns'; export { default as comment } from './library/comment'; +export { default as commentAuthor } from './library/comment-author'; export { default as cover } from './library/cover'; export { default as create } from './library/create'; export { default as crop } from './library/crop'; @@ -153,7 +154,6 @@ export { default as postContent } from './library/post-content'; export { default as postComments } from './library/post-comments'; export { default as postCommentsCount } from './library/post-comments-count'; export { default as postCommentsForm } from './library/post-comments-form'; -export { default as postCommentsAuthor } from './library/post-comments-author'; export { default as postDate } from './library/post-date'; export { default as postExcerpt } from './library/post-excerpt'; export { default as postFeaturedImage } from './library/post-featured-image'; diff --git a/packages/icons/src/library/post-comments-author.js b/packages/icons/src/library/comment-author.js similarity index 90% rename from packages/icons/src/library/post-comments-author.js rename to packages/icons/src/library/comment-author.js index 4e8d72e5c5a62..1d55d90a491a1 100644 --- a/packages/icons/src/library/post-comments-author.js +++ b/packages/icons/src/library/comment-author.js @@ -3,7 +3,7 @@ */ import { SVG, Path, Circle } from '@wordpress/primitives'; -const postCommentsAuthor = ( +const commentAuthor = ( ); -export default postCommentsAuthor; +export default commentAuthor; From db11cc3fd53da89c9126520926427ade0a0246db Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Tue, 19 Oct 2021 16:08:51 +0200 Subject: [PATCH 7/8] Unify removing p tag on both editor and frontend --- packages/block-library/src/post-comment-author/edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/post-comment-author/edit.js b/packages/block-library/src/post-comment-author/edit.js index ed4a3f4733ae5..f68b6830e8e2f 100644 --- a/packages/block-library/src/post-comment-author/edit.js +++ b/packages/block-library/src/post-comment-author/edit.js @@ -46,7 +46,7 @@ export default function Edit( { attributes, context, setAttributes } ) { { displayName } ) : ( -

{ displayName }

+ { displayName } ); return ( From bd3ff1325d7c303fb3912fdc1fa4652230a6f930 Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Tue, 19 Oct 2021 16:57:32 +0200 Subject: [PATCH 8/8] Reset p to previous status --- packages/block-library/src/post-comment-author/edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/post-comment-author/edit.js b/packages/block-library/src/post-comment-author/edit.js index f68b6830e8e2f..ed4a3f4733ae5 100644 --- a/packages/block-library/src/post-comment-author/edit.js +++ b/packages/block-library/src/post-comment-author/edit.js @@ -46,7 +46,7 @@ export default function Edit( { attributes, context, setAttributes } ) { { displayName } ) : ( - { displayName } +

{ displayName }

); return (