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

[Post Featured Image]: Show all controls when in context without postId #49609

Merged
merged 1 commit into from
Apr 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 8 additions & 29 deletions packages/block-library/src/post-featured-image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,15 @@ export default function PostFeaturedImageEdit( {
let image;

/**
* A post featured image block placed in a query loop
* does not have image replacement or upload options.
* A Post Featured Image block should not have image replacement
* or upload options in the following cases:
* - Is placed in a Query Loop. This is a consious decision to
* prevent content editing of different posts in Query Loop, and
* this could change in the future.
* - Is in a context where it does not have a postId (for example
* in a template or template part).
*/
if ( ! featuredImage && isDescendentOfQueryLoop ) {
if ( ! featuredImage && ( isDescendentOfQueryLoop || ! postId ) ) {
return (
<>
{ controls }
Expand All @@ -202,32 +207,6 @@ export default function PostFeaturedImageEdit( {
);
}

/**
* A post featured image placed in a block template, outside a query loop,
* does not have a postId and will always be a placeholder image.
* It does not have image replacement, upload, or link options.
*/
if ( ! featuredImage && ! postId ) {
return (
<>
<DimensionControls
clientId={ clientId }
attributes={ attributes }
setAttributes={ setAttributes }
imageSizeOptions={ imageSizeOptions }
/>
<div { ...blockProps }>
{ placeholder() }
<Overlay
attributes={ attributes }
setAttributes={ setAttributes }
clientId={ clientId }
/>
</div>
</>
);
}

const label = __( 'Add a featured image' );
const imageStyles = {
...borderProps.style,
Expand Down