-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Quote: Rename the align attribute to textAlign #42960
Changes from 7 commits
6edad09
45a9863
746c4fb
745786e
976d99f
67d16e7
11ad22b
9112eda
2def1cc
ef50128
5fd2a25
a8057ff
757a999
beb1c9d
46a7b01
686ead6
6367fe6
215d6fc
51e1813
547539d
420beba
46940c5
2aa7d2e
ac28077
fa4566b
f2f96c5
48ef842
844482d
e1d245a
54188a1
92a9b73
f3ef6e7
8434f65
c45e17a
6509edd
ecd78fc
e280bac
f6a6f48
49d93d5
79d760c
57b74b7
7b1be6f
6245a17
1b76aba
7eae1e8
737dda7
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ import classnames from 'classnames'; | |
*/ | ||
import { createBlock, parseWithAttributeSchema } from '@wordpress/blocks'; | ||
import { RichText, useBlockProps } from '@wordpress/block-editor'; | ||
import { compose } from '@wordpress/compose'; | ||
|
||
export const migrateToQuoteV2 = ( attributes ) => { | ||
const { value, ...restAttributes } = attributes; | ||
|
@@ -34,6 +35,76 @@ export const migrateToQuoteV2 = ( attributes ) => { | |
]; | ||
}; | ||
|
||
const TEXT_ALIGN_OPTIONS = [ 'left', 'right', 'center' ]; | ||
|
||
// Migrate existing text alignment settings to the renamed attribute. | ||
const migrateTextAlign = ( attributes ) => { | ||
aaronrobertshaw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { align, ...rest } = attributes; | ||
// Check if there are valid alignments stored in the old attribute | ||
// and assign them to the new attribute name. | ||
return TEXT_ALIGN_OPTIONS.includes( align ) | ||
? { ...rest, textAlign: align } | ||
: attributes; | ||
}; | ||
|
||
// Renamed the 'align' attribute to 'textAlign'. | ||
const v4 = { | ||
attributes: { | ||
carolinan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
value: { | ||
type: 'string', | ||
source: 'html', | ||
selector: 'blockquote', | ||
multiline: 'p', | ||
default: '', | ||
__experimentalRole: 'content', | ||
}, | ||
citation: { | ||
type: 'string', | ||
source: 'html', | ||
selector: 'cite', | ||
default: '', | ||
__experimentalRole: 'content', | ||
}, | ||
textAlign: { | ||
type: 'string', | ||
}, | ||
}, | ||
supports: { | ||
align: [ 'wide', 'full' ], | ||
anchor: true, | ||
__experimentalSlashInserter: true, | ||
typography: { | ||
fontSize: true, | ||
lineHeight: true, | ||
__experimentalFontStyle: true, | ||
__experimentalFontWeight: true, | ||
__experimentalLetterSpacing: true, | ||
__experimentalTextTransform: true, | ||
__experimentalDefaultControls: { | ||
fontSize: true, | ||
fontAppearance: true, | ||
}, | ||
}, | ||
}, | ||
save( { attributes } ) { | ||
const { textAlign, value, citation } = attributes; | ||
|
||
const className = classnames( { | ||
[ `has-text-align-${ textAlign }` ]: textAlign, | ||
} ); | ||
|
||
return ( | ||
<blockquote { ...useBlockProps.save( { className } ) }> | ||
<RichText.Content multiline value={ value } /> | ||
{ ! RichText.isEmpty( citation ) && ( | ||
<RichText.Content tagName="cite" value={ citation } /> | ||
) } | ||
</blockquote> | ||
); | ||
}, | ||
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. I believe this save function should be a snapshot of the state of the save function prior to the changes in this PR. I.e. if we switch this version back to using |
||
migrate: compose( migrateToQuoteV2, migrateTextAlign ), | ||
ntsekouras marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
const v3 = { | ||
attributes: { | ||
value: { | ||
|
@@ -239,4 +310,4 @@ const v0 = { | |
* | ||
* See block-deprecation.md | ||
*/ | ||
export default [ v3, v2, v1, v0 ]; | ||
export default [ v4, v3, v2, v1, v0 ]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<!-- wp:quote {"align":"right"} --> | ||
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 right. The final html should have the new attribute.. 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. There is something wrong with the deprecation still. @andrewserong suggested (above) that the fixture files should be unchanged. 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.
Yes, that seems like it might be the case.
I think I might have been wrong about that, apologies, I think I might have missed some nuance in earlier reviews. In principle the block markup of this fixture should be unchanged (that is, we'd expect the HTML to be 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. Who is the best person to ping to review the deprecation? 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. It could just be me but the adoption of the That said, I agree, the results of this deprecation fixture aren't correct. As @andrewserong noted, the text align class should still be present and the attribute in the bloc comment delimiter updated to Fixing |
||
<blockquote class="wp-block-quote has-text-align-right"><!-- wp:paragraph --> | ||
<blockquote class="wp-block-quote"><!-- wp:paragraph --> | ||
<p>Testing deprecated quote block...</p> | ||
<!-- /wp:paragraph --><cite>...with a caption</cite></blockquote> | ||
<!-- /wp:quote --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it could help to split out the adoption of align support into a follow-up PR to avoid confusion and draw a clear line between the renaming of the old attribute and the new one.