-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Media & Text: Respect image_default_link_type option #74295
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
base: trunk
Are you sure you want to change the base?
Conversation
When the WordPress `image_default_link_type` option is set to `file` or `post`, the Image block and Gallery block automatically link images to the media file or attachment page upon selection. This behavior was missing from the Media & Text block. This commit updates the `attributesFromMedia` function in the Media & Text block to read the WordPress default link setting from `window.wp.media.view.settings.defaultProps.link` when no `linkDestination` is already set, following the same pattern used by the Image block. The fix: - Adds the `LINK_DESTINATION_NONE` constant to the Media & Text block - Reads the WordPress default link type option when selecting an image - Maps WordPress constants (`file`, `post`) to Gutenberg constants (`media`, `attachment`) - Sets both `linkDestination` and `href` attributes accordingly - Only applies to images, not videos Fixes #60222
The TODO comment mentioned updating the media-text block, which is now addressed in the previous commit.
|
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. |
|
Size Change: +83 B (0%) Total Size: 2.59 MB
ℹ️ View Unchanged
|
Fixes #60222
This PR updates the Media & Text block to respect the WordPress
image_default_link_typeoption when selecting images.When the
image_default_link_typeoption is set tofileorpost, the Image block and Gallery block automatically link images to the media file or attachment page upon selection. However, the Media & Text block was not respecting this setting.This was noted in the Image block code with a TODO comment: "fix this in a follow up PR, requires updating media-text and ui component.
This PR just fixes the issue following exactly the same logic we use on image and gallery blocks:
linkDestinationis not already set when an image is selectedwindow.wp.media.view.settings.defaultProps.linkfile,post) to Gutenberg constants (media,attachment)linkDestinationandhrefattributes accordinglyThe fix only applies to images, not videos (matching the behavior of other blocks).
Testing Instructions
Also test:
image_default_link_typetopostshould link to the attachment pageimage_default_link_typetononeshould not add any linklinkDestinationshould not be affectedlinkDestination