Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Gallery Block: Support gaps that define column/row gaps.
  • Loading branch information
dd32 authored May 18, 2022
commit e06e1def0d2733449d1d37b5ade99e503d48ed6b
18 changes: 16 additions & 2 deletions packages/block-library/src/gallery/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,32 @@ function block_core_gallery_render( $attributes, $content ) {
// Skip if gap value contains unsupported characters.
// Regex for CSS value borrowed from `safecss_filter_attr`, and used here
// because we only want to match against the value, not the CSS attribute.
$gap = preg_match( '%[\\\(&=}]|/\*%', $gap ) ? null : $gap;
if ( is_array( $gap ) ) {
foreach ( $gap as $key => $value ) {
$gap[ $key ] = $value && preg_match( '%[\\\(&=}]|/\*%', $value ) ? null : $value;
}
} else {
$gap = $gap_value && preg_match( '%[\\\(&=}]|/\*%', $gap ) ? null : $gap;
}

$class = wp_unique_id( 'wp-block-gallery-' );
$content = preg_replace(
'/' . preg_quote( 'class="', '/' ) . '/',
'class="' . $class . ' ',
$content,
1
);

// --gallery-block--gutter-size is deprecated. --wp--style--gallery-gap-default should be used by themes that want to set a default
// gap on the gallery.
$gap_value = $gap ? $gap : 'var( --wp--style--gallery-gap-default, var( --gallery-block--gutter-size, var( --wp--style--block-gap, 0.5em ) ) )';
$style = '.' . $class . '{ --wp--style--unstable-gallery-gap: ' . $gap_value . '; gap: ' . $gap_value . '}';
if ( is_array( $gap_value ) ) {
$gap_row = isset( $gap_value['top'] ) ? $gap_value['top'] : '0.5em';
$gap_column = isset( $gap_value['left'] ) ? $gap_value['left'] : '0.5em';
$gap_value = $gap_row === $gap_column ? $gap_row : $gap_row . ' ' . $gap_column;
}

$style = '.' . $class . '{ --wp--style--unstable-gallery-gap: ' . $gap_value . '; gap: ' . $gap_value . '}';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it looks like --wp--style--unstable-gallery-gap is used for calculating the width of columns, so this value always needs to be a single column value, not the combined value if I'm reading this correctly. (@glendaviesnz might be able to correct me on this).

I think that might mean that on line 73, we should set that to always be the column value. E.g.

$gap_value = $gap_column;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it looks like --wp--style--unstable-gallery-gap is used for calculating the width of columns

Yep, this definitely should always be the single column value or the calculation of the column widths will fail.

// Ideally styles should be loaded in the head, but blocks may be parsed
// after that, so loading in the footer for now.
// See https://core.trac.wordpress.org/ticket/53494.
Expand Down