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

Feature: add custom alt tag to "HeaderImage" #7335

Merged
merged 9 commits into from
May 7, 2024
7 changes: 7 additions & 0 deletions src/DonationForms/Properties/FormSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ class FormSettings implements Arrayable, Jsonable
*/
public $designSettingsImageUrl;

/**
* @unreleased
* @var string
*/
public $designSettingsImageAlt;

/**
* @since 3.4.0
* @var string
Expand Down Expand Up @@ -321,6 +327,7 @@ public static function fromArray(array $array): self
) ? $array['pdfSettings'] : [];

$self->designSettingsImageUrl = $array['designSettingsImageUrl'] ?? '';
$self->designSettingsImageAlt = $array['designSettingsImageAlt'] ?? $self->formTitle;
$self->designSettingsImageStyle = ! empty($array['designSettingsImageStyle']) ? new DesignSettingsImageStyle(
$array['designSettingsImageStyle']
) : DesignSettingsImageStyle::BACKGROUND();
Expand Down
2 changes: 1 addition & 1 deletion src/DonationForms/resources/app/form/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function Header({form}: {form: DonationForm}) {
form.settings?.designSettingsImageUrl && (
<HeaderImageTemplate
url={form.settings?.designSettingsImageUrl}
alt={form.settings?.formTitle}
alt={form.settings?.designSettingsImageAlt || form.settings?.formTitle}
color={form.settings?.designSettingsImageColor}
opacity={form.settings?.designSettingsImageOpacity}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import './styles.scss';
type MediaLibrary = {
id: string;
value: string;
onChange: (url: string) => void;
onChange: (url: string, alt: string) => void;
reset: () => void;
label: string;
help?: string;
Expand Down Expand Up @@ -44,7 +44,7 @@ export default function MediaLibrary({id, value, onChange, label, help, actionLa
// Get media attachment details from the frame state
var attachment = frame.state().get('selection').first().toJSON();

onChange(attachment.url);
onChange(attachment.url, attachment.alt);
});

// Finally, open the modal on click
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,18 @@ export default function Header({dispatch, publishSettings}) {
label={__('Image', 'give')}
actionLabel={__('Upload Image', 'give')}
value={designSettingsImageUrl}
onChange={(designSettingsImageUrl) => {
onChange={(designSettingsImageUrl, designSettingsImageAlt) => {
dispatch(
setFormSettings({
designSettingsImageUrl,
designSettingsImageAlt,
designSettingsImageStyle,
})
);

publishSettings({
designSettingsImageUrl,
designSettingsImageAlt,
designSettingsImageStyle,
});
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export type FormSettings = {
pdfSettings: object;
designSettingsImageUrl: string;
designSettingsImageStyle: string;
designSettingsImageAlt: string;
designSettingsLogoUrl: string;
designSettingsLogoPosition: string;
designSettingsSectionStyle: string;
Expand Down
Loading