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

Framework: Rename MediaPlaceholder onSelectUrl prop as onSelectURL #7982

Merged
merged 2 commits into from
Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 15 additions & 9 deletions core-blocks/audio/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class AudioEdit extends Component {
};

this.toggleAttribute = this.toggleAttribute.bind( this );
this.onSelectURL = this.onSelectURL.bind( this );
}

toggleAttribute( attribute ) {
Expand All @@ -41,6 +42,19 @@ class AudioEdit extends Component {
};
}

onSelectURL( newSrc ) {
const { attributes, setAttributes } = this.props;
const { src } = attributes;

// Set the block's src from the edit component's state, and switch off
// the editing UI.
if ( newSrc !== src ) {
setAttributes( { src: newSrc, id: undefined } );
}

this.setState( { editing: false } );
}

render() {
const { autoplay, caption, loop, preload, src } = this.props.attributes;
const { setAttributes, isSelected, className, noticeOperations, noticeUI } = this.props;
Expand All @@ -61,14 +75,6 @@ class AudioEdit extends Component {
setAttributes( { src: media.url, id: media.id } );
this.setState( { src: media.url, editing: false } );
};
const onSelectUrl = ( newSrc ) => {
// set the block's src from the edit component's state, and switch off the editing UI
if ( newSrc !== src ) {
setAttributes( { src: newSrc, id: undefined } );
}
this.setState( { editing: false } );
};

if ( editing ) {
return (
<MediaPlaceholder
Expand All @@ -79,7 +85,7 @@ class AudioEdit extends Component {
} }
className={ className }
onSelect={ onSelectAudio }
onSelectUrl={ onSelectUrl }
onSelectURL={ this.onSelectURL }
accept="audio/*"
type="audio"
value={ this.props.attributes }
Expand Down
23 changes: 15 additions & 8 deletions core-blocks/video/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class VideoEdit extends Component {
};

this.toggleAttribute = this.toggleAttribute.bind( this );
this.onSelectURL = this.onSelectURL.bind( this );
}

toggleAttribute( attribute ) {
Expand All @@ -40,6 +41,19 @@ class VideoEdit extends Component {
};
}

onSelectURL( newSrc ) {
const { attributes, setAttributes } = this.props;
const { src } = attributes;

// Set the block's src from the edit component's state, and switch off
// the editing UI.
if ( newSrc !== src ) {
setAttributes( { src: newSrc, id: undefined } );
}

this.setState( { editing: false } );
}

render() {
const { autoplay, caption, controls, loop, muted, src } = this.props.attributes;
const { setAttributes, isSelected, className, noticeOperations, noticeUI } = this.props;
Expand All @@ -60,13 +74,6 @@ class VideoEdit extends Component {
setAttributes( { src: media.url, id: media.id } );
this.setState( { src: media.url, editing: false } );
};
const onSelectUrl = ( newSrc ) => {
// set the block's src from the edit component's state, and switch off the editing UI
if ( newSrc !== src ) {
setAttributes( { src: newSrc, id: undefined } );
}
this.setState( { editing: false } );
};

if ( editing ) {
return (
Expand All @@ -78,7 +85,7 @@ class VideoEdit extends Component {
} }
className={ className }
onSelect={ onSelectVideo }
onSelectUrl={ onSelectUrl }
onSelectURL={ this.onSelectURL }
accept="video/*"
type="video"
value={ this.props.attributes }
Expand Down
1 change: 1 addition & 0 deletions docs/reference/deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Gutenberg's deprecation policy is intended to support backwards-compatibility fo
- `wp.utils.buildTermsTree` has been removed.
- `wp.utils.decodeEntities` has been removed. Please use `wp.htmlEntities.decodeEntities` instead.
- All references to a block's `uid` have been replaced with equivalent props and selectors for `clientId`.
- The `MediaPlaceholder` component `onSelectUrl` prop has been renamed to `onSelectURL`.

## 3.4.0

Expand Down
24 changes: 22 additions & 2 deletions editor/components/media-placeholder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
import deprecated from '@wordpress/deprecated';

/**
* Internal dependencies
Expand Down Expand Up @@ -54,7 +55,25 @@ class MediaPlaceholder extends Component {
onSubmitSrc( event ) {
event.preventDefault();
if ( this.state.src ) {
this.props.onSelectUrl( this.state.src );
if ( this.props.onSelectUrl ) {
// TODO: In removing deprecation, ensure to simplify rendering
// to avoid checking for `onSelectUrl`. It also allows this
// function to be simplified to avoid truthiness test on
// `onSelectURL`, since it's required for the form invoking
// this function to be rendered at all.
deprecated( 'MediaPlaceholder `onSelectUrl` prop', {
alternative: '`onSelectURL` prop',
plugin: 'Gutenberg',
version: 'v3.5',
hint: 'The prop has been renamed.',
} );

this.props.onSelectUrl( this.state.src );
}

if ( this.props.onSelectURL ) {
this.props.onSelectURL( this.state.src );
}
}
}

Expand Down Expand Up @@ -82,6 +101,7 @@ class MediaPlaceholder extends Component {
labels,
onSelect,
value = {},
onSelectURL,
onSelectUrl,
onHTMLDrop = noop,
multiple = false,
Expand All @@ -101,7 +121,7 @@ class MediaPlaceholder extends Component {
onFilesDrop={ this.onFilesUpload }
onHTMLDrop={ onHTMLDrop }
/>
{ onSelectUrl && (
{ ( onSelectUrl || onSelectURL ) && (
<form onSubmit={ this.onSubmitSrc }>
<input
type="url"
Expand Down