Skip to content

Commit

Permalink
Allow Image Widget value to be an object in which case we use the '@id'…
Browse files Browse the repository at this point in the history
… for value of the Image Sidebar preview (#6156)
  • Loading branch information
ichim-david authored Jul 29, 2024
1 parent 8530234 commit 88e1894
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/volto/news/6156.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Allow `ImageWidget` value to be an object and use the `@id` to get the value if present.
This is useful for fields that were using the `object_browser` widget previously to set values. @ichim-david
11 changes: 6 additions & 5 deletions packages/volto/src/components/manage/Widgets/ImageWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const UnconnectedImageInput = (props) => {
placeholderLinkInput = '',
onSelectItem,
} = props;
const imageValue = value?.[0]?.['@id'] || value;

const intl = useIntl();
const linkEditor = useLinkEditor();
Expand Down Expand Up @@ -155,7 +156,7 @@ const UnconnectedImageInput = (props) => {
}, [restrictFileUpload]);
const onDragLeave = React.useCallback(() => setDragging(false), []);

return value ? (
return imageValue ? (
<div
className="image-upload-widget-image"
onClick={onFocus}
Expand All @@ -166,9 +167,9 @@ const UnconnectedImageInput = (props) => {
<img
className={props.className}
src={
isInternalURL(value)
? `${flattenToAppURL(value)}/@@images/image/${imageSize}`
: value
isInternalURL(imageValue)
? `${flattenToAppURL(imageValue)}/@@images/image/${imageSize}`
: imageValue
}
alt=""
/>
Expand Down Expand Up @@ -272,7 +273,7 @@ const UnconnectedImageInput = (props) => {
</div>
{linkEditor.anchorNode && (
<linkEditor.LinkEditor
value={value}
value={imageValue}
placeholder={
placeholderLinkInput ||
intl.formatMessage(messages.linkAnImage)
Expand Down

0 comments on commit 88e1894

Please sign in to comment.