Skip to content

Commit

Permalink
Always prefer "large" image size (#11682)
Browse files Browse the repository at this point in the history
Prefer "large" image size (when available) for Gallery, Image and Media and Text blocks.
  • Loading branch information
azaozz authored Nov 15, 2018
1 parent a502e1c commit e583606
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/block-library/src/cover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export const settings = {
}
mediaType = media.type;
}

setAttributes( {
url: media.url,
id: media.id,
Expand Down
6 changes: 4 additions & 2 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External Dependencies
*/
import { filter, pick } from 'lodash';
import { filter, pick, get } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -45,7 +45,9 @@ export function defaultColumnsNumber( attributes ) {
}

export const pickRelevantMediaFiles = ( image ) => {
return pick( image, [ 'alt', 'id', 'link', 'url', 'caption' ] );
const imageProps = pick( image, [ 'alt', 'id', 'link', 'caption' ] );
imageProps.url = get( image, [ 'sizes', 'large', 'url' ] ) || get( image, [ 'media_details', 'sizes', 'large', 'source_url' ] ) || image.url;
return imageProps;
};

class GalleryEdit extends Component {
Expand Down
4 changes: 3 additions & 1 deletion packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ const LINK_DESTINATION_CUSTOM = 'custom';
const ALLOWED_MEDIA_TYPES = [ 'image' ];

export const pickRelevantMediaFiles = ( image ) => {
return pick( image, [ 'alt', 'id', 'link', 'url', 'caption' ] );
const imageProps = pick( image, [ 'alt', 'id', 'link', 'caption' ] );
imageProps.url = get( image, [ 'sizes', 'large', 'url' ] ) || get( image, [ 'media_details', 'sizes', 'large', 'source_url' ] ) || image.url;
return imageProps;
};

/**
Expand Down
9 changes: 8 additions & 1 deletion packages/block-library/src/media-text/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import classnames from 'classnames';
import { get } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -50,6 +51,7 @@ class MediaTextEdit extends Component {
const { setAttributes } = this.props;

let mediaType;
let src;
// for media selections originated from a file upload.
if ( media.media_type ) {
if ( media.media_type === 'image' ) {
Expand All @@ -63,11 +65,16 @@ class MediaTextEdit extends Component {
mediaType = media.type;
}

if ( mediaType === 'image' ) {
// Try the "large" size URL, falling back to the "full" size URL below.
src = get( media, [ 'sizes', 'large', 'url' ] ) || get( media, [ 'media_details', 'sizes', 'large', 'source_url' ] );
}

setAttributes( {
mediaAlt: media.alt,
mediaId: media.id,
mediaType,
mediaUrl: media.url,
mediaUrl: src || media.url,
} );
}

Expand Down

0 comments on commit e583606

Please sign in to comment.