Skip to content

Commit

Permalink
Apply default pattern generation from first image instead of last
Browse files Browse the repository at this point in the history
  • Loading branch information
alecgeatches committed Feb 27, 2025
1 parent 73a6bfc commit 8d1d77d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions inc/Editor/BlockPatterns/BlockPatterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ public static function register_default_block_pattern( string $block_name, strin
break;

case 'image_alt':
$bindings['image']['alt'] = [ $field, $name ];
$bindings['images']['alt'][] = [ $field, $name ];
break;

case 'image_url':
$bindings['image']['url'] = [ $field, $name ];
$bindings['images']['url'][] = [ $field, $name ];
break;

case 'html':
Expand Down Expand Up @@ -152,9 +152,17 @@ public static function register_default_block_pattern( string $block_name, strin
$content .= self::populate_template( 'html', self::generate_attribute_bindings( $block_name, $html ) );
}

// If there is an image URL, create two-column layout with left-aligned image.
if ( ! empty( $bindings['image']['url'] ) ) {
$image_bindings = self::generate_attribute_bindings( $block_name, $bindings['image'] );
// If there is an image URL, create two-column layout with left-aligned image of the first image provided.
if ( ! empty( $bindings['images']['url'] ) ) {
$first_image_bindings = [
'url' => $bindings['images']['url'][0],
];

if ( ! empty( $bindings['images']['alt'] ) ) {
$first_image_bindings['alt'] = $bindings['images']['alt'][0];
}

$image_bindings = self::generate_attribute_bindings( $block_name, $first_image_bindings );
$image_content = self::populate_template( 'image', $image_bindings );
$content = sprintf( self::$templates['columns'], $image_content, $content );
}
Expand Down

0 comments on commit 8d1d77d

Please sign in to comment.