Skip to content

Commit

Permalink
Media links: fix linking for images inserted from URL. (#22195)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsilverstein authored Oct 6, 2020
1 parent 0dd98ce commit 029b1d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,16 @@ const ImageURLInputUI = ( {
} );

const getLinkDestinations = () => {
return [
const linkDestinations = [
{
linkDestination: LINK_DESTINATION_MEDIA,
title: __( 'Media File' ),
url: mediaType === 'image' ? mediaUrl : undefined,
icon,
},
{
];
if ( mediaType === 'image' && mediaLink ) {
linkDestinations.push( {
linkDestination: LINK_DESTINATION_ATTACHMENT,
title: __( 'Attachment Page' ),
url: mediaType === 'image' ? mediaLink : undefined,
Expand All @@ -191,8 +193,9 @@ const ImageURLInputUI = ( {
<Path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6z" />
</SVG>
),
},
];
} );
}
return linkDestinations;
};

const onSetHref = ( value ) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export default function Image( {
url={ href || '' }
onChangeUrl={ onSetHref }
linkDestination={ linkDestination }
mediaUrl={ image && image.source_url }
mediaUrl={ ( image && image.source_url ) || url }
mediaLink={ image && image.link }
linkTarget={ linkTarget }
linkClass={ linkClass }
Expand Down

0 comments on commit 029b1d3

Please sign in to comment.