Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the editor settings to pass a mediaUpload handler #14115

Merged
merged 2 commits into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions packages/editor/src/components/media-placeholder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
withFilters,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
import { Component, Fragment } from '@wordpress/element';
import { compose } from '@wordpress/compose';
import { withSelect } from '@wordpress/data';

Expand All @@ -26,7 +26,6 @@ import { withSelect } from '@wordpress/data';
import MediaUpload from '../media-upload';
import MediaUploadCheck from '../media-upload/check';
import URLPopover from '../url-popover';
import { mediaUpload } from '../../utils/';

const InsertFromURLPopover = ( { src, onChange, onSubmit, onClose } ) => (
<URLPopover onClose={ onClose }>
Expand Down Expand Up @@ -104,7 +103,7 @@ export class MediaPlaceholder extends Component {
}

onFilesUpload( files ) {
const { onSelect, multiple, onError, allowedTypes } = this.props;
const { onSelect, multiple, onError, allowedTypes, mediaUpload } = this.props;
const setMedia = multiple ? onSelect : ( [ media ] ) => onSelect( media );
mediaUpload( {
allowedTypes,
Expand Down Expand Up @@ -136,6 +135,7 @@ export class MediaPlaceholder extends Component {
notices,
allowedTypes = [],
hasUploadPermissions,
mediaUpload,
} = this.props;

const {
Expand Down Expand Up @@ -202,19 +202,23 @@ export class MediaPlaceholder extends Component {
notices={ notices }
>
<MediaUploadCheck>
<DropZone
onFilesDrop={ this.onFilesUpload }
onHTMLDrop={ onHTMLDrop }
/>
<FormFileUpload
isLarge
className="editor-media-placeholder__button"
onChange={ this.onUpload }
accept={ accept }
multiple={ multiple }
>
{ __( 'Upload' ) }
</FormFileUpload>
{ !! mediaUpload && (
<Fragment>
<DropZone
onFilesDrop={ this.onFilesUpload }
onHTMLDrop={ onHTMLDrop }
/>
<FormFileUpload
isLarge
className="editor-media-placeholder__button"
onChange={ this.onUpload }
accept={ accept }
multiple={ multiple }
>
{ __( 'Upload' ) }
</FormFileUpload>
</Fragment>
) }
<MediaUpload
gallery={ multiple && this.onlyAllowsImages() }
multiple={ multiple }
Expand Down Expand Up @@ -259,9 +263,11 @@ export class MediaPlaceholder extends Component {

const applyWithSelect = withSelect( ( select ) => {
const { canUser } = select( 'core' );
const { getEditorSettings } = select( 'core/block-editor' );

return {
hasUploadPermissions: defaultTo( canUser( 'create', 'media' ), true ),
mediaUpload: getEditorSettings().__experimentalMediaUpload,
};
} );

Expand Down
3 changes: 3 additions & 0 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { BlockEditorProvider } from '@wordpress/block-editor';
* Internal dependencies
*/
import transformStyles from '../../editor-styles';
import { mediaUpload } from '../../utils';

class EditorProvider extends Component {
constructor( props ) {
super( ...arguments );
Expand Down Expand Up @@ -57,6 +59,7 @@ class EditorProvider extends Component {
onChange: onMetaChange,
},
__experimentalReusableBlocks: reusableBlocks,
__experimentalMediaUpload: mediaUpload,
};
}

Expand Down