From d6fd16ffb7a3aa147b8787826d932a9a7187b69a Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Tue, 16 Jun 2026 16:58:17 +0400 Subject: [PATCH] File Block: Combine audio/video/image to file transforms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `core/audio`, `core/video`, and `core/image` → `core/file` transforms had near-identical bodies, so this merges them into a single transform. Audio/Video use `src`, Image uses `url`, handled via `attributes.src ?? attributes.url`. The `getFilename()` filename fallback (previously only on Image) now applies to all three, so captionless audio/video get a filename instead of none. --- packages/block-library/src/file/transforms.js | 39 +++---------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/packages/block-library/src/file/transforms.js b/packages/block-library/src/file/transforms.js index d2a640ce371bbf..a2317426927de4 100644 --- a/packages/block-library/src/file/transforms.js +++ b/packages/block-library/src/file/transforms.js @@ -62,41 +62,14 @@ const transforms = { }, { type: 'block', - blocks: [ 'core/audio' ], - transform: ( attributes ) => { - return createBlock( 'core/file', { - href: attributes.src, - fileName: attributes.caption, - textLinkHref: attributes.src, - id: attributes.id, - anchor: attributes.anchor, - downloadButtonText, - } ); - }, - }, - { - type: 'block', - blocks: [ 'core/video' ], - transform: ( attributes ) => { - return createBlock( 'core/file', { - href: attributes.src, - fileName: attributes.caption, - textLinkHref: attributes.src, - id: attributes.id, - anchor: attributes.anchor, - downloadButtonText, - } ); - }, - }, - { - type: 'block', - blocks: [ 'core/image' ], + blocks: [ 'core/audio', 'core/video', 'core/image' ], transform: ( attributes ) => { + // Audio/Video use `src`, Image uses `url`. + const href = attributes.src ?? attributes.url; return createBlock( 'core/file', { - href: attributes.url, - fileName: - attributes.caption || getFilename( attributes.url ), - textLinkHref: attributes.url, + href, + fileName: attributes.caption || getFilename( href ), + textLinkHref: href, id: attributes.id, anchor: attributes.anchor, downloadButtonText,