-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add new grid layout type #4625
Add new grid layout type #4625
Conversation
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.
This is testing nicely for me with the changes applied along with repeat
allowed via #4637:
✅ Grid layout test markup works as expected, using auto-fill
rule in grid-template-columns
.
✅ Updating the markup to use a columnCount
attribute with an integer correctly outputs a grid-template-columns
rule with a number based approach for the number of columns.
✅ blockGap
output works correctly, and parses spacing presets correctly.
Values are passed to style engine for output, which is responsible for filtering CSS values via safecss_filter_attr
, so this all looks good to me!
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.
Thanks for the PR @tellthemachines! Looks good to me.
Just a couple of questions about some of the checks that exist in these changes and elsewhere in the file. Not a blocker for this PR, but possibly a follow-up improvement in this file depending on the answers?
} | ||
$gap_value = trim( $combined_gap_value ); | ||
|
||
if ( null !== $gap_value && ! $should_skip_gap_serialization ) { |
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 don't think $gap_value
can ever be null
by this point. Should this be '' !== $gap_value
, or is the condition not needed?
Although I see this is how it's done elsewhere in the file. If it can't be null
by this point, then this could maybe be updated elsewhere in the file in a separate issue to reduce checks and make things a bit cleaner.
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.
Agreed, better look into cleaning all the checks up at once in a separate issue.
foreach ( $gap_sides as $gap_side ) { | ||
$process_value = is_string( $gap_value ) ? $gap_value : _wp_array_get( $gap_value, array( $gap_side ), $fallback_gap_value ); | ||
// Get spacing CSS variable from preset value if provided. | ||
if ( is_string( $process_value ) && str_contains( $process_value, 'var:preset|spacing|' ) ) { |
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.
Won't $process_value
always be a string after the line above? If not, what other type might it be, and is this safe when interpolated on the last line of the foreach()
?
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.
Looks like $gap_value
could be an array, e.g.,
array(
'top' => '12px', // column
'left' => '11px', // row
)
So I think the extra string check makes sense if we're fetching the value of $gap_value['top']
for example?
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.
Checking if $gap_value
is a string makes sense. I was referring to the is_string( $process_value )
. This seems like it's always a string already - The fallback value is documented as a string, values always appear to have units like px
or em
(such as '12px'
if getting top
from your example), and $process_value
is appended to a string without any conversion at the bottom of the foreach()
:
$combined_gap_value .= "$process_value "
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.
$process_value
might possibly be null, but I don't think it could be anything other than string or null.
This logic is repeated for the flex layout type, so might also be worth looking into separately and fixing all instances together.
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.
Oh sorry, I didn't make it down to $combined_gap_value .= "$process_value ";
... now I get it 🤦
I'm pretty sure the assumption is "yes", it's a string, so the extra check is probably redundant (?)
I guess folks could add anything as a style value in theme.json (and they probably do), even if it's contrary to the theme.json schema rules.
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.
LGTM
@@ -287,6 +287,44 @@ function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false | |||
); | |||
} | |||
} | |||
} elseif ( 'grid' === $layout_type ) { |
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.
Need @since
annotation
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.
Oh, thanks! I forget about them half the time 😅
foreach ( $gap_sides as $gap_side ) { | ||
$process_value = is_string( $gap_value ) ? $gap_value : _wp_array_get( $gap_value, array( $gap_side ), $fallback_gap_value ); | ||
// Get spacing CSS variable from preset value if provided. | ||
if ( is_string( $process_value ) && str_contains( $process_value, 'var:preset|spacing|' ) ) { |
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.
Looks like $gap_value
could be an array, e.g.,
array(
'top' => '12px', // column
'left' => '11px', // row
)
So I think the extra string check makes sense if we're fetching the value of $gap_value['top']
for example?
30692a2
to
3cf0439
Compare
3cf0439
to
ff36b0a
Compare
Finally got e2e to pass on this branch so will try committing again 🤞 |
Trac ticket: https://core.trac.wordpress.org/ticket/58554
Introduces the PHP changes from WordPress/gutenberg#49018 (except for the kses filter which will be dealt with separately) and the changes to
layout.php
from WordPress/gutenberg#49050, because they build upon the changes from the first PR.To test this change, check out this branch locally and update the following npm packages:
@wordpress/block-editor": "11.8.0"
"@wordpress/block-library": "8.8.0"
"@wordpress/blocks": "12.8.0"
Then run
npm run postsync-gutenberg-packages
followed bynpm run build:dev
(assuming you're building from src, otherwise runnpm run build
)Then, in the post editor, paste the following block markup:
The grid should look fine in the editor; on the front end it won't show the correct column number without the kses patch to support
repeat
.This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.