Skip to content

Adds transforms functionality to Post comments link and post comments number #70287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

dhruvikpatel18
Copy link
Contributor

What?

Adds bidirectional transform support between Post Comments Link and Post Comments Number blocks.

Closes #53053

Why?

The Post Comments Link and Post Comments Number blocks share similar functionality (both display comment-related information) but currently cannot be transformed into each other. This creates an inconsistent user experience where users need to delete one block and manually recreate the other to switch between displaying a comments link vs. comments count, losing all their styling and configuration in the process.

Testing Instructions

  1. Open a post or page in the block editor
  2. Insert a Post Comments Link block
  3. Click on the block toolbar's transform button (three horizontal dots with arrows)
  4. Select "Post Comments Number" from the transform options
  5. Verify the block transforms correctly and preserves all styling
  6. Transform it back to Post Comments Link and verify styling is still preserved
  7. Repeat the test starting with a Post Comments Number block

Screenshots or screencast

Comment_transforms.mov

@dhruvikpatel18 dhruvikpatel18 marked this pull request as ready for review June 2, 2025 09:09
Copy link

github-actions bot commented Jun 2, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: dhruvikpatel18 <dhruvik18@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: draganescu <andraganescu@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@cbravobernal cbravobernal added [Block] Comments Count Affects the Post Comments Count Block [Block] Comment Link Affects the Comment Link Block [Type] Enhancement A suggestion for improvement. labels Jun 2, 2025
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! This functionality makes sense to me.

Can we keep the textAlign attribute between the transformation?

Center-aligned Comments Link block:

image

When converting to the Comments Count, alignment settings are lost:

image

Code example:

transform: ( { textAlign } ) =>
createBlock( 'core/post-author-name', { textAlign } ),
},

@t-hamano t-hamano added the [Feature] Block Transforms Block transforms from one block to another label Jun 3, 2025
@dhruvikpatel18
Copy link
Contributor Author

@t-hamano Thanks for highlighting, I have added support for textAlign attribute between the transformation.

@dhruvikpatel18 dhruvikpatel18 requested a review from t-hamano June 3, 2025 05:26
@dhruvikpatel18 dhruvikpatel18 requested a review from t-hamano June 3, 2025 10:44
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@t-hamano t-hamano merged commit faecb83 into WordPress:trunk Jun 4, 2025
61 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.0 milestone Jun 4, 2025
chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
… number (WordPress#70287)

* feat: Add transforms functionality to post-comments-count and post-comments-link blocks

* chore: pass textAlign attribute in transforms for post-comments blocks

* chore: refactor transform functions to use destructured textAlign attribute

Co-authored-by: dhruvikpatel18 <dhruvik18@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: draganescu <andraganescu@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Comment Link Affects the Comment Link Block [Block] Comments Count Affects the Post Comments Count Block [Feature] Block Transforms Block transforms from one block to another [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Post comments link should transform to post comments number and vice versa
3 participants