-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Block Library: Add a Post Featured Image block. #19875
Conversation
Wondering if this could use the Image block somehow to avoid duplication of features. |
I think it should use the post featured image component from the editor, but generalizing it will be a bit more involved and should be handled in another PR. |
I'm not certain about that, in the sidebar you just want to assign the featured image but in a template, you want to assign it but also show it, scale it, maybe apply it as a Cover, maybe align it. And all these features are already covered in the Image or cover blocks. So we should be thinking how can we make these work together. |
I think we need a generic image-edit component. Do you think that should block this PR though? |
I'd love @mtias thoughts on this PR and that problem. I know this is something that we discussed briefly before. |
Something that's been brewing in my mind is the possibility of using the |
Ooooh, I've thought about this. We could support registering variations where you can map attributes to entity props, and the framework handles the syncing under the hood. I held back on it because I thought the use cases were too small to warrant supporting this as a top-level API when you can achieve the same thing with minimal code. What do you think, @youknowriad? It's kind of similar to the custom sources API that we ended up deprecating for lack of flexibility to avoid having different ways of doing the same thing. |
Yes, exactly! I think variations have opened up such a door as it'll reduce a lot of pointless duplication while still keeping a sense of autonomy and clarity. My worry is how it might impact the internal handling of the source block (as it'd need to disable certain UIs based on presence of attributes or types of attributes: entity vs editable, etc), where it could create conditional trees that exacerbate the complexity, but it does look, at least conceptually, a good path. We should proceed with caution and see what kind of pitfalls it might create. |
Can you think of other examples where this API would be useful? I think
that the component approach might be better when you consider for example
that most Image block variations would want to add/remove things to the UI
like you said or perhaps even include it within a set of inputs.
|
Interesting idea 👍 I think such API could be useful in a more situations. For example, any RichText entity value (example post title) could be a variation of the Paragraph block. I'm still not sure whether this is a block variation or something else as there's a few things we want to customize:
At the moment, I'm having a hard time thinking of a good flexible API for this though. |
Those are the reasons that make me think an API for this would be so convoluted and seldom used by third parties that it's not worth exploring. |
@youknowriad I think this PR should be merged. It cleanly implements the non-editable part of the block and is something we need to play with themes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, happy to land this as a start.
61a094f
to
edff443
Compare
edff443
to
9ef1843
Compare
if ( ! $post ) { | ||
return ''; | ||
} | ||
return '<p>' . get_the_post_thumbnail( $post ) . '</p>'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semantically, this would be better wrapped with a figure
tag , which should additionally have a class name so that it can be targeted by Theme and Plugin developers.
naturalWidth={ media.media_details.width } | ||
naturalHeight={ media.media_details.height } | ||
> | ||
<img src={ media.source_url } alt="Post Featured Media" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tag should have a class name so that it can be targeted by Theme and Plugin developers. Also, the alt text cannot be translated if it's defined statically.
|
||
export default function PostFeaturedImageEdit() { | ||
if ( ! useEntityId( 'postType', 'post' ) ) { | ||
return 'Post Featured Image Placeholder'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This text cannot be translated if it's defined statically.
Description
This PR adds a new Post Featured Image block akin to the Post Title and Post Content blocks.
How has this been tested?
Types of Changes
New Feature: There is a new Post Featured Image block for template building.
Checklist: