Skip to content

Conversation

@youknowriad
Copy link
Contributor

closes #8219

Add a new editor config: "availableImageSizes" to be able to display the image sizes labels properly in the image block's inspector.

(Needs to be backported to Core once merged cc @pento)

Testing instructions

@youknowriad youknowriad added [Feature] Media Anything that impacts the experience of managing media Backwards Compatibility Issues or PRs that impact backwards compatability labels Nov 1, 2018
@youknowriad youknowriad added this to the 4.3 milestone Nov 1, 2018
@youknowriad youknowriad self-assigned this Nov 1, 2018
@youknowriad youknowriad requested review from a team, antpb and desrosj November 1, 2018 10:29
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.

I added the following filter:

function my_custom_sizes( $sizes ) {
    return array_merge( $sizes, array(
        'full' => __('My Custom Full Size'),
    ) );
}

add_filter( 'image_size_names_choose', 'my_custom_sizes' );

And the full label was successfully changed. I think we need to switch id to slug on the editor defaults but besides that things look good to me 👍

],

availableImageSizes: [
{ id: 'thumbnail', label: __( 'Thumbnail' ) },
Copy link
Member

Choose a reason for hiding this comment

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

I think here we should use slug instead of id, otherwise const availableImageSizesBySlug = keyBy( availableImageSizes, 'slug' );is not going to work.

$sizes[] = 'full';
$size_names = apply_filters(
'image_size_names_choose',
array(
Copy link
Member

Choose a reason for hiding this comment

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

We already have this array duplicated in many places of the WordPress codebase. When backporting this, it may make sense to check if we can use a constant or another approach to avoid this duplication.

@gziolo
Copy link
Member

gziolo commented Nov 2, 2018

Out of curiosity, do you have any idea how does it relate to the existing filter for the size of the featured image:

https://github.com/WordPress/gutenberg/blob/master/packages/editor/src/components/post-featured-image/index.js#L33-L43

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

https://github.com/WordPress/gutenberg/blob/master/docs/extensibility/extending-editor.md#editorpostfeaturedimageimagesize

@youknowriad youknowriad force-pushed the try/fix-image-size-names branch from ca05381 to c57cc66 Compare November 2, 2018 10:12
@youknowriad
Copy link
Contributor Author

@gziolo It doesn't seem like the filter is directly related. Not that I like the idea of a filter, I think we should remove all frontend filters 🤷‍♂️ but it's addressing another use-case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backwards Compatibility Issues or PRs that impact backwards compatability [Feature] Media Anything that impacts the experience of managing media

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image size control don't display proper labels for sizes.

4 participants