Repository navigation
Post Date: Migrate to textAlign block support #75856
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
Changes from 1 commit
cf7fc3c
d5ff6a9
54ddda4
e9ee265
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,3 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import clsx from 'clsx'; | ||
|
|
||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
|
|
@@ -14,7 +9,6 @@ import { | |
| getSettings as getDateSettings, | ||
| } from '@wordpress/date'; | ||
| import { | ||
| AlignmentControl, | ||
| BlockControls, | ||
| InspectorControls, | ||
| store as blockEditorStore, | ||
|
|
@@ -41,19 +35,18 @@ import { store as blocksStore } from '@wordpress/blocks'; | |
| * Internal dependencies | ||
| */ | ||
| import { useToolsPanelDropdownMenuProps } from '../utils/hooks'; | ||
| import useDeprecatedTextAlign from '../utils/deprecated-text-align-attributes'; | ||
|
|
||
| export default function PostDateEdit( { | ||
| attributes, | ||
| context: { postType: postTypeSlug, queryId }, | ||
| setAttributes, | ||
| name, | ||
| } ) { | ||
| const { datetime, textAlign, format, isLink } = attributes; | ||
| const blockProps = useBlockProps( { | ||
| className: clsx( { | ||
| [ `has-text-align-${ textAlign }` ]: textAlign, | ||
| } ), | ||
| } ); | ||
| export default function PostDateEdit( props ) { | ||
| const { | ||
| attributes, | ||
| context: { postType: postTypeSlug, queryId }, | ||
| setAttributes, | ||
| name, | ||
| } = props; | ||
| useDeprecatedTextAlign( props ); | ||
| const { datetime, format, isLink } = attributes; | ||
| const blockProps = useBlockProps(); | ||
| const dropdownMenuProps = useToolsPanelDropdownMenuProps(); | ||
|
|
||
| // Use internal state instead of a ref to make sure that the component | ||
|
|
@@ -129,13 +122,6 @@ export default function PostDateEdit( { | |
| { ( blockEditingMode === 'default' || | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. { ( blockEditingMode === 'default' || ! isDescendentOfQueryLoop ) &&
activeBlockVariationName !== 'post-date-modified' &&
( ! isDescendentOfQueryLoop || ! activeBlockVariationName ) && (
<BlockControls group="block">
<ToolbarGroup>
</ToolbarGroup>
</BlockControls>
) }All of the conditional checks here should be able to be consolidated. |
||
| ! isDescendentOfQueryLoop ) && ( | ||
| <BlockControls group="block"> | ||
| <AlignmentControl | ||
| value={ textAlign } | ||
| onChange={ ( nextAlign ) => { | ||
| setAttributes( { textAlign: nextAlign } ); | ||
| } } | ||
| /> | ||
|
|
||
| { activeBlockVariationName !== 'post-date-modified' && | ||
| ( ! isDescendentOfQueryLoop || | ||
| ! activeBlockVariationName ) && ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <!-- wp:post-date {"textAlign":"left"} /--> | ||
|
|
||
| <!-- wp:post-date {"textAlign":"center"} /--> | ||
|
|
||
| <!-- wp:post-date {"textAlign":"right"} /--> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| [ | ||
| { | ||
| "name": "core/post-date", | ||
| "isValid": true, | ||
| "attributes": { | ||
| "textAlign": "left", | ||
| "isLink": false, | ||
| "metadata": { | ||
| "bindings": { | ||
| "datetime": { | ||
| "source": "core/post-data", | ||
| "args": { | ||
| "field": "date" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "innerBlocks": [] | ||
| }, | ||
| { | ||
| "name": "core/post-date", | ||
| "isValid": true, | ||
| "attributes": { | ||
| "textAlign": "center", | ||
| "isLink": false, | ||
| "metadata": { | ||
| "bindings": { | ||
| "datetime": { | ||
| "source": "core/post-data", | ||
| "args": { | ||
| "field": "date" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "innerBlocks": [] | ||
| }, | ||
| { | ||
| "name": "core/post-date", | ||
| "isValid": true, | ||
| "attributes": { | ||
| "textAlign": "right", | ||
| "isLink": false, | ||
| "metadata": { | ||
| "bindings": { | ||
| "datetime": { | ||
| "source": "core/post-data", | ||
| "args": { | ||
| "field": "date" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "innerBlocks": [] | ||
| } | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| [ | ||
| { | ||
| "blockName": "core/post-date", | ||
| "attrs": { | ||
| "textAlign": "left" | ||
| }, | ||
| "innerBlocks": [], | ||
| "innerHTML": "", | ||
| "innerContent": [] | ||
| }, | ||
| { | ||
| "blockName": null, | ||
| "attrs": {}, | ||
| "innerBlocks": [], | ||
| "innerHTML": "\n\n", | ||
| "innerContent": [ "\n\n" ] | ||
| }, | ||
| { | ||
| "blockName": "core/post-date", | ||
| "attrs": { | ||
| "textAlign": "center" | ||
| }, | ||
| "innerBlocks": [], | ||
| "innerHTML": "", | ||
| "innerContent": [] | ||
| }, | ||
| { | ||
| "blockName": null, | ||
| "attrs": {}, | ||
| "innerBlocks": [], | ||
| "innerHTML": "\n\n", | ||
| "innerContent": [ "\n\n" ] | ||
| }, | ||
| { | ||
| "blockName": "core/post-date", | ||
| "attrs": { | ||
| "textAlign": "right" | ||
| }, | ||
| "innerBlocks": [], | ||
| "innerHTML": "", | ||
| "innerContent": [] | ||
| } | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <!-- wp:post-date {"metadata":{"bindings":{"datetime":{"source":"core/post-data","args":{"field":"date"}}}}} /--> | ||
|
|
||
| <!-- wp:post-date {"metadata":{"bindings":{"datetime":{"source":"core/post-data","args":{"field":"date"}}}}} /--> | ||
|
|
||
| <!-- wp:post-date {"metadata":{"bindings":{"datetime":{"source":"core/post-data","args":{"field":"date"}}}}} /--> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem to be the expected result. The text alignment seems to be discarded.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The I fixed this by updating
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The v2 deprecation is a necessary step to migrate block attributes to Block Bindings. Adding exclusion rules will cause unintended problems. Please try the following:
<!-- wp:post-date {"displayType":"modified"} /-->
<!-- wp:post-date {"displayType":"modified", "textAlign":"right"} /-->
✅ <!-- wp:post-date {"metadata":{"bindings":{"datetime":{"source":"core/post-data","args":{"field":"modified"}}}},"className":"wp-block-post-date__modified-date"} /-->❌ <!-- wp:post-date {"datetime":"2026-03-16T10:14:11.214Z","style":{"typography":{"textAlign":"right"}}} /-->
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The solution is probably to add |
||
Uh oh!
There was an error while loading. Please reload this page.