-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Package blocks: Introduce a utility for getting the block image #68910
base: trunk
Are you sure you want to change the base?
Conversation
Add a utility function to the Blocks API that gets an image URL. Blocks can register a __experimentalImage setting to pass any chosen image URL depending on context. A context may be for example the list-view.
Size Change: +141 B (+0.01%) Total Size: 1.84 MB
ℹ️ View Unchanged
|
Flaky tests detected in 7882523. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/13004800325
|
block.attributes?.mediaAlt || | ||
'', | ||
clientId: block.clientId, | ||
}, |
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.
The alt
is not currently used. I included it to match getImage
. Perhaps it can be useful in the future.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Do I need to add a manual changelog entry for an experimental feature? |
What?
Add a basic utility function to the Blocks API that gets a custom image URL from a block.
Blocks can register a
__experimentalImage
setting to pass any chosen image URL depending on context. A context may be for example thelist-view.
For #53684
What the PR does not do:
It does not update the code that displays the preview image from the image or gallery blocks in the List View,
Why?
The List View shows a small preview of the image used in image block and gallery.
But it is hardcoded to the
url
attribute of the image block.Instead of hardcoding it, an API can be used. Such an API can be used to present the image in other parts of the interface if the need and want should occur, and not be limited to the list view.
See #53381 (comment)
The implementation is similar to that of
__experimentalLabel
The reason why this utility is helpful is because the block can use any
url
as the image source. Different blocks may name the source url for their images differently. For example, in the Media & Text block, the attribute is called "mediaUrl"Or, the block may want to use a specific custom image that is not a block attribute.
How?
The pull request updates the Media & Text block and the Cover block to include a new setting called
__experimentalImage
.This setting uses the block attributes and the context, and conditionally returns the url of the image.
The pull request adds a function named
getBlockImage
to the utility file of the blocks API.It collects
__experimentalImage
from the block type and conditionally returns the url.The API exports the function as
__experimentalGetBlockImage
.Finally,
__experimentalGetBlockImage
is imported in the List View, inuseListViewImages
,and is used to determine the url of the miniature image to show in the List View.
Testing Instructions
Insert and add images to:
An image block
A cover block
A media & text block
Open the List View. Confirm if the mentioned blocks have image previews.
Screen readers
The image is a background in a span that has
aria-hidden="true"
, this is unchanged and it does not need testing with a screen reader.Screenshots or screencast