Add layout and block spacing support to Latest Posts block#77989
Add layout and block spacing support to Latest Posts block#77989tellthemachines wants to merge 5 commits into
Conversation
|
Size Change: +587 B (+0.01%) Total Size: 7.98 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Flaky tests detected in 601548d. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/26207163167
|
bb4677d to
92b61a7
Compare
| 'string' !== typeof oldAttributes.categories | ||
| ) { | ||
| return oldAttributes; | ||
| } |
There was a problem hiding this comment.
had to add this check because we need to run this before the layout migration, and if we don't check whether categories actually exists it just goes and adds an array of them anyway
| ! postCount | ||
| ? MAX_POSTS_COLUMNS | ||
| : Math.min( MAX_POSTS_COLUMNS, postCount ) | ||
| } |
There was a problem hiding this comment.
Removing the old max here so it matches the Post Template controls.
| [ `columns-${ columns }` ]: postLayout === 'grid', | ||
| [ `columns-${ columnCount }` ]: | ||
| layoutType === 'grid' && columnCount, | ||
| 'has-native-responsive-grid': |
There was a problem hiding this comment.
This block has the same responsive fallback as Post Template so we're adding the same back compat workaround.
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
ramonjd
left a comment
There was a problem hiding this comment.
It took me way too long to realize I had to click on the "grid" layout to test 🤦🏻
Question: does this make the existing postLayout and columns attributes in block.json deprecated? Do they stay there for any reason? (Assuming backwards compat)
| ...attributesWithoutLegacyLayout, | ||
| layout: { | ||
| type: postLayout === 'grid' ? 'grid' : 'default', | ||
| ...( postLayout === 'grid' && columns && { columnCount: columns } ), |
There was a problem hiding this comment.
Does there need to be a default here, or does it flow down from block.json? (column: 3)
E.g., columnCount: columns ?? 3
There was a problem hiding this comment.
It'll be whatever is set on the legacy block, which might be that default from block.json or something else if user has changed it.
There was a problem hiding this comment.
ah actually I think we should ensure the legacy attribs are present in the deprecation, then they can be removed from the block.json
| }, | ||
| migrate: ( oldAttributes ) => | ||
| migratePostLayout( migrateCategories( oldAttributes ) ), | ||
| isEligible: ( { postLayout } ) => postLayout, |
There was a problem hiding this comment.
Does the migration have to run just for 'grid' or all layouts?
There was a problem hiding this comment.
all layouts because we're also converting the "list" layout to the "default" type.
| html: false, | ||
| }, | ||
| migrate: migrateCategories, | ||
| isEligible: ( { categories } ) => |
There was a problem hiding this comment.
Apologies, I haven't had my nose in deprecations for a long time.
Does this deprecation see the original raw attributes or the already-migrated attributes?
Just wondering if this will run on the original attributes and replace the migration result from before. If so maybe a ! postLayout check would stop that?
I don't know! 😄
There was a problem hiding this comment.
As I understand it the migrations always run in sequence, so if the block is eligible for the categories migration it'll run that, and if it's eligible for the layout one it'll run categories and then layout on whatever categories spat out. I tested this on blocks with legacy layouts and it seemed to work fine.
sorry, I didn't think to add that step explicitly 😅
Oh I think they can be removed! Looking at #49050 as an example, we removed the |
What?
Similar to #49050 and #77411.
Adds layout and block spacing support to Latest Posts to replace its custom list/grid styles.
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast
(note that Layout panel is now in the Styles tab)
Use of AI Tools
Written by GPT 5.5.
leaving as a draft until I've reviewed it properly.this has now been human-reviewed.