Skip to content

Commit

Permalink
Fix onSelectURL to manage default LinkDestination values other
Browse files Browse the repository at this point in the history
than "none".
  • Loading branch information
jesusangel committed Dec 27, 2019
1 parent f7096a9 commit 773d6ec
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class ImageEdit extends Component {
} else if ( value === LINK_DESTINATION_MEDIA ) {
href = ( image && image.source_url ) || attributes.url;
} else if ( value === LINK_DESTINATION_ATTACHMENT ) {
href = image && image.link;
href = ( image && image.link ) || attributes.link;
} else {
href = attributes.href;
}
Expand All @@ -285,13 +285,21 @@ export class ImageEdit extends Component {
}

onSelectURL( newURL ) {
const { url } = this.props.attributes;
const { url, linkDestination } = this.props.attributes;
let newLinkDestination = linkDestination;

// Images from URL doesn't have an attachment link
if ( linkDestination === LINK_DESTINATION_ATTACHMENT ) {
newLinkDestination = LINK_DESTINATION_NONE;
}

if ( newURL !== url ) {
this.props.setAttributes( {
url: newURL,
href: linkDestination === LINK_DESTINATION_MEDIA ? newURL : null,
id: undefined,
sizeSlug: DEFAULT_SIZE_SLUG,
linkDestination: newLinkDestination,
} );
}
}
Expand Down

0 comments on commit 773d6ec

Please sign in to comment.