Skip to content

Commit

Permalink
Merge pull request #86 from studiopress/remove/editor-dependency
Browse files Browse the repository at this point in the history
Prevent PHP notice on Widgets page
  • Loading branch information
kienstra authored Jul 20, 2021
2 parents a2aedc4 + 8a87160 commit 6df3457
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions js/src/block-editor/controls/test/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ jest.mock( '@wordpress/api-fetch', () => {
} );
} );

jest.mock( '@wordpress/data/build/components/use-select', () =>
jest.fn( () => false )
);

// @todo: remove this when the console warning no longer appears.
// Expected mock function not to be called but it was called with:
// ["wp.components.DropZoneProvider is deprecated. Note: wp.component.DropZone no longer needs a provider. wp.components.DropZoneProvider is safe to remove from your code."]
Expand Down
4 changes: 4 additions & 0 deletions js/src/block-editor/controls/test/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ jest.mock( '@wordpress/api-fetch', () => {
} );
} );

jest.mock( '@wordpress/data/build/components/use-select', () =>
jest.fn( () => false )
);

// @todo: remove this when the console warning no longer appears.
// Expected mock function not to be called but it was called with:
// ["wp.components.DropZoneProvider is deprecated. Note: wp.component.DropZone no longer needs a provider. wp.components.DropZoneProvider is safe to remove from your code."]
Expand Down
10 changes: 9 additions & 1 deletion js/src/block-editor/hooks/useMedia.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* WordPress dependencies
*/
import { store as blockEditorStore } from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import { mediaUpload } from '@wordpress/editor';
import { mediaUpload as legacyMediaUpload } from '@wordpress/editor';
import { useEffect, useState } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';

Expand Down Expand Up @@ -58,6 +59,13 @@ const useMedia = ( fieldValue, onChange, allowedTypes ) => {
return select( 'core' ).getMedia( fieldValue );
} );

/* @type {function|undefined} */
const mediaUpload = useSelect( ( select ) => {
// @ts-ignore The function isn't in the declaration file.
const { getSettings } = select( blockEditorStore );
return getSettings()?.mediaUpload || legacyMediaUpload;
} );

useEffect( () => {
if ( media?.source_url ) {
setMediaSrc( media.source_url );
Expand Down
2 changes: 1 addition & 1 deletion php/Blocks/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function editor_assets() {
wp_enqueue_script(
$js_handle,
$this->assets['url']['entry'],
$js_config['dependencies'],
[],
$js_config['version'],
true
);
Expand Down

0 comments on commit 6df3457

Please sign in to comment.