Skip to content

Commit 6851886

Browse files
authored
Reflects revert in 6446878 (#41221)
And reverts #40982 since it's related to the original issue: #41161
1 parent 78cea0f commit 6851886

File tree

4 files changed

+3
-68
lines changed

4 files changed

+3
-68
lines changed

packages/block-editor/src/components/media-placeholder/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ export function MediaPlaceholder( {
7373
onDoubleClick,
7474
onFilesPreUpload = noop,
7575
onHTMLDrop = noop,
76-
onClose = noop,
7776
children,
7877
mediaLibraryButton,
7978
placeholder,
@@ -327,7 +326,6 @@ export function MediaPlaceholder( {
327326
gallery={ multiple && onlyAllowsImages() }
328327
multiple={ multiple }
329328
onSelect={ onSelect }
330-
onClose={ onClose }
331329
allowedTypes={ allowedTypes }
332330
value={
333331
Array.isArray( value )

packages/block-editor/src/components/media-replace-flow/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const MediaReplaceFlow = ( {
4242
onSelect,
4343
onSelectURL,
4444
onFilesUpload = noop,
45-
onCloseModal = noop,
4645
name = __( 'Replace' ),
4746
createNotice,
4847
removeNotice,
@@ -158,7 +157,6 @@ const MediaReplaceFlow = ( {
158157
selectMedia( media, onClose )
159158
}
160159
allowedTypes={ allowedTypes }
161-
onClose={ onCloseModal }
162160
render={ ( { open } ) => (
163161
<MenuItem icon={ mediaIcon } onClick={ open }>
164162
{ __( 'Open Media Library' ) }

packages/block-library/src/image/edit.js

+1-53
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
store as blockEditorStore,
2020
} from '@wordpress/block-editor';
2121
import { useEffect, useRef, useState } from '@wordpress/element';
22-
import { __, sprintf } from '@wordpress/i18n';
22+
import { __ } from '@wordpress/i18n';
2323
import { image as icon } from '@wordpress/icons';
2424

2525
/**
@@ -85,20 +85,6 @@ function hasDefaultSize( image, defaultSize ) {
8585
);
8686
}
8787

88-
/**
89-
* Checks if a media attachment object has been "destroyed",
90-
* that is, removed from the media library. The core Media Library
91-
* adds a `destroyed` property to a deleted attachment object in the media collection.
92-
*
93-
* @param {number} id The attachment id.
94-
*
95-
* @return {boolean} Whether the image has been destroyed.
96-
*/
97-
export function isMediaDestroyed( id ) {
98-
const attachment = window?.wp?.media?.attachment( id ) || {};
99-
return attachment.destroyed;
100-
}
101-
10288
export function ImageEdit( {
10389
attributes,
10490
setAttributes,
@@ -139,41 +125,6 @@ export function ImageEdit( {
139125
return pick( getSettings(), [ 'imageDefaultSize', 'mediaUpload' ] );
140126
}, [] );
141127

142-
// A callback passed to MediaUpload,
143-
// fired when the media modal closes.
144-
function onCloseModal() {
145-
if ( isMediaDestroyed( attributes?.id ) ) {
146-
setAttributes( {
147-
url: undefined,
148-
id: undefined,
149-
} );
150-
}
151-
}
152-
153-
/*
154-
Runs an error callback if the image does not load.
155-
If the error callback is triggered, we infer that that image
156-
has been deleted.
157-
*/
158-
function onImageError( isReplaced = false ) {
159-
noticeOperations.removeAllNotices();
160-
noticeOperations.createErrorNotice(
161-
sprintf(
162-
/* translators: %s url or missing image */
163-
__( 'Error loading image: %s' ),
164-
url
165-
)
166-
);
167-
// If the image block was not replaced with an embed,
168-
// clear the attributes and trigger the placeholder.
169-
if ( ! isReplaced ) {
170-
setAttributes( {
171-
url: undefined,
172-
id: undefined,
173-
} );
174-
}
175-
}
176-
177128
function onUploadError( message ) {
178129
noticeOperations.removeAllNotices();
179130
noticeOperations.createErrorNotice( message );
@@ -372,8 +323,6 @@ export function ImageEdit( {
372323
containerRef={ ref }
373324
context={ context }
374325
clientId={ clientId }
375-
onCloseModal={ onCloseModal }
376-
onImageLoadError={ onImageError }
377326
/>
378327
) }
379328
{ ! url && (
@@ -390,7 +339,6 @@ export function ImageEdit( {
390339
onSelectURL={ onSelectURL }
391340
notices={ noticeUI }
392341
onError={ onUploadError }
393-
onClose={ onCloseModal }
394342
accept="image/*"
395343
allowedTypes={ ALLOWED_MEDIA_TYPES }
396344
value={ { id, src } }

packages/block-library/src/image/image.js

+2-11
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import { store as coreStore } from '@wordpress/core-data';
4747
*/
4848
import { createUpgradedEmbedBlock } from '../embed/util';
4949
import useClientWidth from './use-client-width';
50-
import { isExternalImage, isMediaDestroyed } from './edit';
50+
import { isExternalImage } from './edit';
5151

5252
/**
5353
* Module constants
@@ -76,14 +76,12 @@ export default function Image( {
7676
isSelected,
7777
insertBlocksAfter,
7878
onReplace,
79-
onCloseModal,
8079
onSelectImage,
8180
onSelectURL,
8281
onUploadError,
8382
containerRef,
8483
context,
8584
clientId,
86-
onImageLoadError,
8785
} ) {
8886
const imageRef = useRef();
8987
const captionRef = useRef();
@@ -225,13 +223,10 @@ export default function Image( {
225223
// Check if there's an embed block that handles this URL, e.g., instagram URL.
226224
// See: https://github.com/WordPress/gutenberg/pull/11472
227225
const embedBlock = createUpgradedEmbedBlock( { attributes: { url } } );
228-
const shouldReplace = undefined !== embedBlock;
229226

230-
if ( shouldReplace ) {
227+
if ( undefined !== embedBlock ) {
231228
onReplace( embedBlock );
232229
}
233-
234-
onImageLoadError( shouldReplace );
235230
}
236231

237232
function onSetHref( props ) {
@@ -303,9 +298,6 @@ export default function Image( {
303298
if ( ! isSelected ) {
304299
setIsEditingImage( false );
305300
}
306-
if ( isSelected && isMediaDestroyed( id ) ) {
307-
onImageLoadError();
308-
}
309301
}, [ isSelected ] );
310302

311303
const canEditImage = id && naturalWidth && naturalHeight && imageEditing;
@@ -369,7 +361,6 @@ export default function Image( {
369361
onSelect={ onSelectImage }
370362
onSelectURL={ onSelectURL }
371363
onError={ onUploadError }
372-
onCloseModal={ onCloseModal }
373364
/>
374365
</BlockControls>
375366
) }

0 commit comments

Comments
 (0)