Skip to content

Commit

Permalink
feat: Allow attachedImageWidget to use also object browser values for…
Browse files Browse the repository at this point in the history
… backwards compatibility - refs #258136
  • Loading branch information
dobri1408 committed Nov 28, 2023
1 parent 436b844 commit 031a597
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Widget/AttachedImageWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ const messages = defineMessages({
},
});

const formatURL = (url) => {
if (url === undefined) return '';
if (typeof url === 'string') return url;
if (Array.isArray(url)) return formatURL(url?.[0]);
if (typeof url === 'object') return formatURL(url?.['@id']);
};

export class AttachedImageWidget extends Component {
/**
* Property types.
Expand Down Expand Up @@ -210,11 +217,11 @@ export class AttachedImageWidget extends Component {
<div className="preview">
<img
src={
isInternalURL(this.props.value)
isInternalURL(formatURL(this.props.value))
? `${flattenToAppURL(
this.props.value,
formatURL(this.props.value),
)}/@@images/image/preview`
: this.props.value
: formatURL(this.props.value)
}
alt="Preview"
/>
Expand Down

0 comments on commit 031a597

Please sign in to comment.