Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default featured image size #15844

Merged
merged 3 commits into from
Nov 4, 2019

Conversation

derweili
Copy link
Contributor

@derweili derweili commented May 27, 2019

Description

Fixed the default image sizes used for featured images displayed in the editor:
Fixes: #15842, #14084

How has this been tested?

Verified with a linter on my local environment.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@youknowriad youknowriad requested a review from a team May 27, 2019 15:45
@youknowriad youknowriad added Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code [Type] Bug An existing feature does not function as intended [Feature] Media Anything that impacts the experience of managing media labels May 27, 2019
@@ -31,7 +31,7 @@ function PostFeaturedImage( { currentPostId, featuredImageId, onUpdateImage, onR

let mediaWidth, mediaHeight, mediaSourceUrl;
if ( media ) {
const mediaSize = applyFilters( 'editor.PostFeaturedImage.imageSize', 'post-thumbnail', media.id, currentPostId );
const mediaSize = applyFilters( 'editor.PostFeaturedImage.imageSize', 'thumbnail', media.id, currentPostId );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @derweili, thank you for your contribution 👍
I verified that the classic editor also loads post thumbnail when it is available.
E.g: this is the markup classic editor provided (the src is for the post-thumbnail size):
Screenshot 2019-05-27 at 22 19 23

I verified that if post_thumbnail is not available thumbnail size used in the classic editor while in Gutenberg full size is used. I think maybe we should follow the same logic verify if post_thumbnail is available and if yes we should use it, if not Gutenberg verifies if thumbnail is available.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me. The post-thumbnail image size is available if the theme adds support for post thumbnails.

thumbnail on the other hand is always there, but is usually something like 150x150 big.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swissspidy thumbnail is not always there.

If the uploaded image is smaller than thumbnail size (defaut 150 x 150) the thumbnail size is missing.
full is the only size that's always available.

I think that the image sizes should be chosen in the following order:

  1. Load post-thumbnail (still use the editor.PostFeaturedImage.imageSize filter)
  2. If post-thumbnail is not available, load thumbnail
  3. If both post-thumbnail and thumbnail are not available, use the full size.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @derweili, that seems a good plan 👍

Copy link
Contributor Author

@derweili derweili Jul 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jorgefilipecosta I implemented the changes as described above.

I reset the mediaSize to post-thumbnail and added a new fallbackMediaSize which has the value thumbnail by default.

I also added a new filter editor.PostFeaturedImage.fallbackImageSize to modify the new fallbackMediaSize, similar to the existing filter editor.PostFeaturedImage.imageSize

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

full is the only size that's always available.

The frustrating thing here is that media.media_details.sizes is an empty object when the image is smaller than the thumbnail size. If it always contained a size then we could do something to pick the appropriate size in the order of preference.

Given the current structure of the media.media_details object, this change looks good to me.

Alternatively, we could make another change so sizes always contains full at a minimum.

Any thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the improvements @derweili this PR seems to be on a good path I left a suggestion.

Alternatively, we could make another change so sizes always contains full at a minimum.

It would be good if originally that was the case but now it may be risky to change the structure as there may be external code/filters that is expecting and empty array.
I think the current direction addresses the problem well.

@gziolo gziolo added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Jun 3, 2019
mediaSize reset to post-thumbnail
fallbackMediaSize added and set to thumbnail

`editor.PostFeaturedImage.fallbackImageSize` filter added to modify the new fallbackMediaSize
@@ -32,11 +32,20 @@ function PostFeaturedImage( { currentPostId, featuredImageId, onUpdateImage, onR
let mediaWidth, mediaHeight, mediaSourceUrl;
if ( media ) {
const mediaSize = applyFilters( 'editor.PostFeaturedImage.imageSize', 'post-thumbnail', media.id, currentPostId );
const fallbackMediaSize = applyFilters( 'editor.PostFeaturedImage.fallbackImageSize', 'thumbnail', media.id, currentPostId );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need a new filter for the fallback? Can't we use the existing filter e.g:

const fallbackMediaSize = applyFilters( 'editor.PostFeaturedImage. imageSize', 'thumbnail', media.id, currentPostId );

Another thing to consider is that the filters used here may have complex logic it would be nice to only compute the fallbackMediaSize if the mediaSize does not exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jorgefilipecosta

I implemented you suggestions in the latest commit.

  • The fallback size now uses the same filter as the default size.
  • The fallback size now get computed only when default size is missing

@@ -31,7 +31,7 @@ function PostFeaturedImage( { currentPostId, featuredImageId, onUpdateImage, onR

let mediaWidth, mediaHeight, mediaSourceUrl;
if ( media ) {
const mediaSize = applyFilters( 'editor.PostFeaturedImage.imageSize', 'post-thumbnail', media.id, currentPostId );
const mediaSize = applyFilters( 'editor.PostFeaturedImage.imageSize', 'thumbnail', media.id, currentPostId );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the improvements @derweili this PR seems to be on a good path I left a suggestion.

Alternatively, we could make another change so sizes always contains full at a minimum.

It would be good if originally that was the case but now it may be risky to change the structure as there may be external code/filters that is expecting and empty array.
I think the current direction addresses the problem well.

Copy link
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for all the interactions @derweili I left a suggestion but other than that the PR seems to be very close to the finish line.

improved: the fallback size will now be calculated only if the default size is not available.
changed: the fallback size now uses the same filter as the default size
Copy link
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@jorgefilipecosta jorgefilipecosta merged commit 61753df into WordPress:master Nov 4, 2019
daniloercoli added a commit that referenced this pull request Nov 5, 2019
…rnmobile/gb-mobile-872-JSApplicationIllegalArgumentException-in-RCTAztecView

* 'master' of https://github.com/WordPress/gutenberg: (56 commits)
  Update: Default gradients. (#18214)
  Fix: setting a preset color on pullquote default style makes the block invalid (#18194)
  Fix default featured image size (#15844)
  Fix postmeta radio regression. (#18183)
  Components: Switch screen-reader-text to VisuallyHidden (#18165)
  [rnmobile] Release 1.16.0 to master (#18261)
  Template Loader: Add theme block template resolution. (#18247)
  Add a README file for storybook directory (#18245)
  Add editor-gradient-presets to get_theme_support (#17841)
  Add "Image Title Attribute" as an editable attribute on the image block (#11070)
  enables horizontal movers in social blocks (#18234)
  [RNMobile] Add mobile Spacer component (#17896)
  Add experimental `ResponsiveBlockControl` component (#16790)
  Fix mover for floats. (#18230)
  Rename Component to WPComponent in docstring (#18226)
  Colors Selector: replace `Aa` text by SVG icon (#18222)
  Removed gif from README (#18200)
  makes the submenu items stacked vertically (#18221)
  Add block navigator to sidebar panel for nav block (#18202)
  Fix: consecutive updates may trigger a blocks reset (#18219)
  ...
@derweili derweili deleted the featured-image-size branch November 8, 2019 13:00
@youknowriad youknowriad added this to the Gutenberg 6.9 milestone Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Media Anything that impacts the experience of managing media First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Featured image uses wrong default size
6 participants