Skip to content
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

Apply default pattern generation from first image instead of last #398

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
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
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
Loading