Skip to content

Commit

Permalink
MediaReplaceFlow: Check permissions before displaying the 'Media Libr…
Browse files Browse the repository at this point in the history
…ary' menu item
  • Loading branch information
Mamaduka committed Mar 23, 2023
1 parent 3481fe8 commit d7424d4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
60 changes: 36 additions & 24 deletions packages/block-editor/src/components/media-replace-flow/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -58,6 +63,7 @@ const MediaReplaceFlow = ( {
const mediaUpload = useSelect( ( select ) => {
return select( blockEditorStore ).getSettings().mediaUpload;
}, [] );
const canUpload = !! mediaUpload;
const editMediaButtonRef = useRef();
const errorNoticeID = `block-editor/media-replace-flow/error-notice/${ ++uniqueId }`;

Expand Down Expand Up @@ -152,7 +158,7 @@ const MediaReplaceFlow = ( {
renderContent={ ( { onClose } ) => (
<>
<NavigableMenu className="block-editor-media-replace-flow__media-upload-menu">
<>
<MediaUploadCheck>
<MediaUpload
gallery={ gallery }
addToGallery={ addToGallery }
Expand All @@ -171,28 +177,26 @@ const MediaReplaceFlow = ( {
</MenuItem>
) }
/>
<MediaUploadCheck>
<FormFileUpload
onChange={ ( event ) => {
uploadFiles( event, onClose );
} }
accept={ accept }
multiple={ multiple }
render={ ( { openFileDialog } ) => {
return (
<MenuItem
icon={ upload }
onClick={ () => {
openFileDialog();
} }
>
{ __( 'Upload' ) }
</MenuItem>
);
} }
/>
</MediaUploadCheck>
</>
<FormFileUpload
onChange={ ( event ) => {
uploadFiles( event, onClose );
} }
accept={ accept }
multiple={ multiple }
render={ ( { openFileDialog } ) => {
return (
<MenuItem
icon={ upload }
onClick={ () => {
openFileDialog();
} }
>
{ __( 'Upload' ) }
</MenuItem>
);
} }
/>
</MediaUploadCheck>
{ onToggleFeaturedImage && (
<MenuItem
icon={ postFeaturedImage }
Expand All @@ -206,7 +210,15 @@ const MediaReplaceFlow = ( {
</NavigableMenu>
{ onSelectURL && (
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
<form className="block-editor-media-flow__url-input">
<form
className={ classnames(
'block-editor-media-flow__url-input',
{
'has-siblings':
! canUpload && ! onToggleFeaturedImage,
}
) }
>
<span className="block-editor-media-replace-flow__image-url-label">
{ __( 'Current media URL:' ) }
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
margin-left: -$grid-unit-10;
padding: $grid-unit-20;

&.has-siblings {
border-top: none;
margin-top: 0;
}

.block-editor-media-replace-flow__image-url-label {
display: block;
top: $grid-unit-20;
Expand Down

0 comments on commit d7424d4

Please sign in to comment.