Skip to content

Commit

Permalink
Media Replace Flow: Add title for attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed Feb 2, 2024
1 parent cc7ac02 commit d64d872
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const MediaReplaceFlow = ( {
addToGallery,
handleUpload = true,
popoverProps,
title,
} ) => {
const mediaUpload = useSelect( ( select ) => {
return select( blockEditorStore ).getSettings().mediaUpload;
Expand Down Expand Up @@ -220,7 +221,7 @@ const MediaReplaceFlow = ( {
</span>

<LinkControl
value={ { url: mediaURL } }
value={ { title, url: mediaURL } }
settings={ [] }
showSuggestions={ false }
onChange={ ( { url } ) => {
Expand Down
10 changes: 10 additions & 0 deletions packages/block-library/src/audio/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { __, _x } from '@wordpress/i18n';
import { useDispatch, useSelect } from '@wordpress/data';
import { audio as icon } from '@wordpress/icons';
import { store as noticesStore } from '@wordpress/notices';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand All @@ -49,6 +50,14 @@ function AudioEdit( {
const isTemporaryAudio = ! id && isBlobURL( src );
const { getSettings } = useSelect( blockEditorStore );

const audioFile = useSelect(
( select ) =>
id && isSingleSelected
? select( coreStore ).getMedia( id, { context: 'view' } )
: null,
[ id, isSingleSelected ]
);

useEffect( () => {
if ( ! id && isBlobURL( src ) ) {
const file = getBlobByURL( src );
Expand Down Expand Up @@ -153,6 +162,7 @@ function AudioEdit( {
onSelect={ onSelectAudio }
onSelectURL={ onSelectURL }
onError={ onUploadError }
title={ audioFile?.title?.rendered }
/>
</BlockControls>
) }
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ export default function Image( {
onSelect={ onSelectImage }
onSelectURL={ onSelectURL }
onError={ onUploadError }
title={ image?.title?.rendered }
/>
</BlockControls>
) }
Expand Down
10 changes: 10 additions & 0 deletions packages/block-library/src/video/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { useInstanceId } from '@wordpress/compose';
import { useDispatch, useSelect } from '@wordpress/data';
import { video as icon } from '@wordpress/icons';
import { store as noticesStore } from '@wordpress/notices';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand Down Expand Up @@ -77,6 +78,14 @@ function VideoEdit( {
const isTemporaryVideo = ! id && isBlobURL( src );
const { getSettings } = useSelect( blockEditorStore );

const videoFile = useSelect(
( select ) =>
id && isSingleSelected
? select( coreStore ).getMedia( id, { context: 'view' } )
: null,
[ id, isSingleSelected ]
);

useEffect( () => {
if ( ! id && isBlobURL( src ) ) {
const file = getBlobByURL( src );
Expand Down Expand Up @@ -201,6 +210,7 @@ function VideoEdit( {
onSelect={ onSelectVideo }
onSelectURL={ onSelectURL }
onError={ onUploadError }
title={ videoFile?.title?.rendered }
/>
</BlockControls>
</>
Expand Down

0 comments on commit d64d872

Please sign in to comment.