Skip to content

Commit da4c5d5

Browse files
glendaviesnzGlen Davies
andauthored
Gallery block: fix bug with link destination default option not being set (#38310)
Co-authored-by: Glen Davies <glen.davies@a8c.com>
1 parent da50872 commit da4c5d5

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export const LINK_DESTINATION_NONE = 'none';
22
export const LINK_DESTINATION_MEDIA = 'media';
33
export const LINK_DESTINATION_ATTACHMENT = 'attachment';
4+
export const LINK_DESTINATION_MEDIA_WP_CORE = 'file';
5+
export const LINK_DESTINATION_ATTACHMENT_WP_CORE = 'post';

packages/block-library/src/gallery/utils.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
LINK_DESTINATION_ATTACHMENT,
66
LINK_DESTINATION_MEDIA,
77
LINK_DESTINATION_NONE,
8+
LINK_DESTINATION_MEDIA_WP_CORE,
9+
LINK_DESTINATION_ATTACHMENT_WP_CORE,
810
} from './constants';
911
import {
1012
LINK_DESTINATION_ATTACHMENT as IMAGE_LINK_DESTINATION_ATTACHMENT,
@@ -21,15 +23,17 @@ import {
2123
* @return {Object} New attributes to assign to image block.
2224
*/
2325
export function getHrefAndDestination( image, destination ) {
24-
// Need to determine the URL that the selected destination maps to.
25-
// Gutenberg and WordPress use different constants so the new link
26-
// destination also needs to be tweaked.
26+
// Gutenberg and WordPress use different constants so if image_default_link_type
27+
// option is set we need to map from the WP Core values.
28+
2729
switch ( destination ) {
30+
case LINK_DESTINATION_MEDIA_WP_CORE:
2831
case LINK_DESTINATION_MEDIA:
2932
return {
3033
href: image?.source_url || image?.url, // eslint-disable-line camelcase
3134
linkDestination: IMAGE_LINK_DESTINATION_MEDIA,
3235
};
36+
case LINK_DESTINATION_ATTACHMENT_WP_CORE:
3337
case LINK_DESTINATION_ATTACHMENT:
3438
return {
3539
href: image?.link,

0 commit comments

Comments
 (0)