From bc28780addbb80a92ee2e3e16baeb5a92762ddd9 Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Sat, 7 Feb 2026 12:19:01 +0530 Subject: [PATCH 1/4] Post Comments Form: Migrate to text-align block support --- docs/reference-guides/core-blocks.md | 3 +- .../src/post-comments-form/block.json | 12 ++-- .../src/post-comments-form/deprecated.js | 69 +++++++++++++++++++ .../src/post-comments-form/edit.js | 44 +++--------- .../src/post-comments-form/index.js | 2 + ...re__post-comments-form__deprecated-v1.html | 5 ++ ...re__post-comments-form__deprecated-v1.json | 38 ++++++++++ ...t-comments-form__deprecated-v1.parsed.json | 43 ++++++++++++ ...mments-form__deprecated-v1.serialized.html | 5 ++ 9 files changed, 178 insertions(+), 43 deletions(-) create mode 100644 packages/block-library/src/post-comments-form/deprecated.js create mode 100644 test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.html create mode 100644 test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.json create mode 100644 test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.parsed.json create mode 100644 test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.serialized.html diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index ae187eab57b26d..e49081c0456086 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -683,8 +683,7 @@ Display a post's comments form. ([Source](https://github.com/WordPress/gutenberg - **Name:** core/post-comments-form - **Category:** theme -- **Supports:** anchor, color (background, gradients, heading, link, text), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~ -- **Attributes:** textAlign +- **Supports:** anchor, color (background, gradients, heading, link, text), spacing (margin, padding), typography (fontSize, lineHeight, textAlign), ~~html~~ ## Comments Link diff --git a/packages/block-library/src/post-comments-form/block.json b/packages/block-library/src/post-comments-form/block.json index a3d6c49026a486..c9e9caa91d0815 100644 --- a/packages/block-library/src/post-comments-form/block.json +++ b/packages/block-library/src/post-comments-form/block.json @@ -6,11 +6,6 @@ "category": "theme", "description": "Display a post's comments form.", "textdomain": "default", - "attributes": { - "textAlign": { - "type": "string" - } - }, "usesContext": [ "postId", "postType" ], "supports": { "anchor": true, @@ -31,6 +26,7 @@ "typography": { "fontSize": true, "lineHeight": true, + "textAlign": true, "__experimentalFontStyle": true, "__experimentalFontWeight": true, "__experimentalLetterSpacing": true, @@ -60,7 +56,11 @@ ], "example": { "attributes": { - "textAlign": "center" + "style": { + "typography": { + "textAlign": "center" + } + } } } } diff --git a/packages/block-library/src/post-comments-form/deprecated.js b/packages/block-library/src/post-comments-form/deprecated.js new file mode 100644 index 00000000000000..37a0b86cd5b838 --- /dev/null +++ b/packages/block-library/src/post-comments-form/deprecated.js @@ -0,0 +1,69 @@ +/** + * Internal dependencies + */ +import migrateTextAlign from '../utils/migrate-text-align'; + +const v1 = { + attributes: { + textAlign: { + type: 'string', + }, + }, + supports: { + anchor: true, + html: false, + spacing: { + margin: true, + padding: true, + }, + color: { + gradients: true, + heading: true, + link: true, + __experimentalDefaultControls: { + background: true, + text: true, + }, + }, + typography: { + fontSize: true, + lineHeight: true, + __experimentalFontFamily: true, + __experimentalFontWeight: true, + __experimentalFontStyle: true, + __experimentalTextTransform: true, + __experimentalTextDecoration: true, + __experimentalLetterSpacing: true, + __experimentalDefaultControls: { + fontSize: true, + }, + }, + interactivity: { + clientNavigation: true, + }, + __experimentalBorder: { + radius: true, + color: true, + width: true, + style: true, + __experimentalDefaultControls: { + radius: true, + color: true, + width: true, + style: true, + }, + }, + }, + migrate: migrateTextAlign, + isEligible( attributes ) { + return ( + !! attributes.textAlign || + !! attributes.className?.match( + /\bhas-text-align-(left|center|right)\b/ + ) + ); + }, + save: () => null, +}; + +export default [ v1 ]; \ No newline at end of file diff --git a/packages/block-library/src/post-comments-form/edit.js b/packages/block-library/src/post-comments-form/edit.js index 11089cbe627ffa..1ae81946b9e9b7 100644 --- a/packages/block-library/src/post-comments-form/edit.js +++ b/packages/block-library/src/post-comments-form/edit.js @@ -1,16 +1,7 @@ -/** - * External dependencies - */ -import clsx from 'clsx'; - /** * WordPress dependencies */ -import { - AlignmentControl, - BlockControls, - useBlockProps, -} from '@wordpress/block-editor'; +import { useBlockProps } from '@wordpress/block-editor'; import { VisuallyHidden } from '@wordpress/components'; import { useInstanceId } from '@wordpress/compose'; import { __, sprintf } from '@wordpress/i18n'; @@ -20,40 +11,23 @@ import { __, sprintf } from '@wordpress/i18n'; */ import CommentsForm from './form'; -export default function PostCommentsFormEdit( { - attributes, - context, - setAttributes, -} ) { - const { textAlign } = attributes; +export default function PostCommentsFormEdit( { context } ) { const { postId, postType } = context; const instanceId = useInstanceId( PostCommentsFormEdit ); const instanceIdDesc = sprintf( 'comments-form-edit-%d-desc', instanceId ); const blockProps = useBlockProps( { - className: clsx( { - [ `has-text-align-${ textAlign }` ]: textAlign, - } ), 'aria-describedby': instanceIdDesc, } ); return ( - <> - - { - setAttributes( { textAlign: nextAlign } ); - } } - /> - -
- - - { __( 'Comments form disabled in editor.' ) } - -
- +
+ + + { __( 'Comments form disabled in editor.' ) } + +
); + } diff --git a/packages/block-library/src/post-comments-form/index.js b/packages/block-library/src/post-comments-form/index.js index 4d0444194241de..96afd2d0f48c3b 100644 --- a/packages/block-library/src/post-comments-form/index.js +++ b/packages/block-library/src/post-comments-form/index.js @@ -9,6 +9,7 @@ import { postCommentsForm as icon } from '@wordpress/icons'; import initBlock from '../utils/init-block'; import metadata from './block.json'; import edit from './edit'; +import deprecated from './deprecated'; const { name } = metadata; export { metadata, name }; @@ -16,6 +17,7 @@ export { metadata, name }; export const settings = { icon, edit, + deprecated, }; export const init = () => initBlock( { name, metadata, settings } ); diff --git a/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.html b/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.html new file mode 100644 index 00000000000000..7cee4020f9322c --- /dev/null +++ b/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.html @@ -0,0 +1,5 @@ + + + + + diff --git a/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.json b/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.json new file mode 100644 index 00000000000000..7ba8ef4bed6a42 --- /dev/null +++ b/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.json @@ -0,0 +1,38 @@ +[ + { + "name": "core/post-comments-form", + "isValid": true, + "attributes": { + "style": { + "typography": { + "textAlign": "left" + } + } + }, + "innerBlocks": [] + }, + { + "name": "core/post-comments-form", + "isValid": true, + "attributes": { + "style": { + "typography": { + "textAlign": "center" + } + } + }, + "innerBlocks": [] + }, + { + "name": "core/post-comments-form", + "isValid": true, + "attributes": { + "style": { + "typography": { + "textAlign": "right" + } + } + }, + "innerBlocks": [] + } +] \ No newline at end of file diff --git a/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.parsed.json b/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.parsed.json new file mode 100644 index 00000000000000..7e9ce03ce54d91 --- /dev/null +++ b/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.parsed.json @@ -0,0 +1,43 @@ +[ + { + "blockName": "core/post-comments-form", + "attrs": { + "textAlign": "left" + }, + "innerBlocks": [], + "innerHTML": "", + "innerContent": [] + }, + { + "blockName": null, + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n\n", + "innerContent": [ "\n\n" ] + }, + { + "blockName": "core/post-comments-form", + "attrs": { + "textAlign": "center" + }, + "innerBlocks": [], + "innerHTML": "", + "innerContent": [] + }, + { + "blockName": null, + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n\n", + "innerContent": [ "\n\n" ] + }, + { + "blockName": "core/post-comments-form", + "attrs": { + "textAlign": "right" + }, + "innerBlocks": [], + "innerHTML": "", + "innerContent": [] + } +] \ No newline at end of file diff --git a/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.serialized.html b/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.serialized.html new file mode 100644 index 00000000000000..ee94c6fdf232b3 --- /dev/null +++ b/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.serialized.html @@ -0,0 +1,5 @@ + + + + + From e5f4e1a03ff3d71567db0ccad276bb11edbb0a61 Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Sat, 7 Feb 2026 12:25:21 +0530 Subject: [PATCH 2/4] Post Comments Form: Migrate to text-align block support --- packages/block-library/src/post-comments-form/deprecated.js | 2 +- .../blocks/core__post-comments-form__deprecated-v1.json | 2 +- .../blocks/core__post-comments-form__deprecated-v1.parsed.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/post-comments-form/deprecated.js b/packages/block-library/src/post-comments-form/deprecated.js index 37a0b86cd5b838..4888ee0d4a0b22 100644 --- a/packages/block-library/src/post-comments-form/deprecated.js +++ b/packages/block-library/src/post-comments-form/deprecated.js @@ -66,4 +66,4 @@ const v1 = { save: () => null, }; -export default [ v1 ]; \ No newline at end of file +export default [ v1 ]; diff --git a/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.json b/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.json index 7ba8ef4bed6a42..ee08d9525518a3 100644 --- a/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.json +++ b/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.json @@ -35,4 +35,4 @@ }, "innerBlocks": [] } -] \ No newline at end of file +] diff --git a/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.parsed.json b/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.parsed.json index 7e9ce03ce54d91..58d00fa2876eed 100644 --- a/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.parsed.json +++ b/test/integration/fixtures/blocks/core__post-comments-form__deprecated-v1.parsed.json @@ -40,4 +40,4 @@ "innerHTML": "", "innerContent": [] } -] \ No newline at end of file +] From 94aa07e90657c8aa30b32b5682b1eb06810e8edb Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Sat, 7 Feb 2026 13:23:22 +0530 Subject: [PATCH 3/4] Post Comments Form: Migrate to text-align block support --- packages/block-library/src/post-comments-form/edit.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/block-library/src/post-comments-form/edit.js b/packages/block-library/src/post-comments-form/edit.js index 1ae81946b9e9b7..336609afa9fe8e 100644 --- a/packages/block-library/src/post-comments-form/edit.js +++ b/packages/block-library/src/post-comments-form/edit.js @@ -29,5 +29,4 @@ export default function PostCommentsFormEdit( { context } ) { ); - -} +} \ No newline at end of file From dec0af867fff56456a8b189d721e3b0975094486 Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Sat, 7 Feb 2026 14:47:59 +0530 Subject: [PATCH 4/4] Update edit.js --- packages/block-library/src/post-comments-form/edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/post-comments-form/edit.js b/packages/block-library/src/post-comments-form/edit.js index 336609afa9fe8e..75d1d5358363bc 100644 --- a/packages/block-library/src/post-comments-form/edit.js +++ b/packages/block-library/src/post-comments-form/edit.js @@ -29,4 +29,4 @@ export default function PostCommentsFormEdit( { context } ) { ); -} \ No newline at end of file +}