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

Fix: Maintain aspect ratio for the Campaign Cover Image block #7718

Merged
2 changes: 0 additions & 2 deletions src/Campaigns/Blocks/CampaignCover/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,13 @@ export default function Edit({attributes, setAttributes, toggleSelection}: EditP
className={'givewp-campaign-cover-block-preview__image'}
src={campaign?.image}
alt={attributes.alt ?? __('Campaign Image', 'give')}
style={{width: '100%', height: '100%'}}
/>
</ResizableBox>
) : (
<img
className={'givewp-campaign-cover-block-preview__image'}
src={campaign?.image}
alt={attributes.alt ?? __('Campaign Image', 'give')}
style={{width: '100%', height: '100%'}}
/>
))}
</CampaignSelector>
Expand Down
16 changes: 8 additions & 8 deletions src/Campaigns/Blocks/CampaignCover/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
use Give\Campaigns\Models\Campaign;
use Give\Campaigns\Repositories\CampaignRepository;

if ( ! isset($attributes['campaignId'])) {
if (!isset($attributes['campaignId'])) {
return;
}

/** @var Campaign $campaign */
$campaign = give(CampaignRepository::class)->getById($attributes['campaignId']);

if ( ! $campaign) {
if (!$campaign) {
return;
}

Expand All @@ -21,11 +21,11 @@

// Only assign width and height if the alignment is NOT "full" or "wide"
if ($attributes['align'] !== 'full' && $attributes['align'] !== 'wide') {
$width = isset($attributes['width']) ? $attributes['width'] : '100%';
$height = isset($attributes['height']) ? $attributes['height'] : '100%';
$widthStyle = isset($attributes['width']) ? "width: {$attributes['width']}px;" : '';
$heightStyle = isset($attributes['height']) ? "max-height: {$attributes['height']}px;" : '';
} else {
$width = 'auto';
$height = 'auto';
$widthStyle = 'width: auto;';
$heightStyle = 'height: auto;';
}
?>

Expand All @@ -35,8 +35,8 @@
src="<?php echo esc_url($campaign->image); ?>"
alt="<?php echo esc_attr($altText); ?>"
style="
width:<?php echo $width ?>px;
height: <?php echo $height ?>px;
<?php echo esc_attr($widthStyle) ?>
<?php echo esc_attr($heightStyle) ?>
border-radius: 8px;"
/>
</figure>
Loading