Skip to content

Commit

Permalink
Image: Add the ability for a plugin to disable Image Editor (#23966)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaz authored and ellatrix committed Jul 20, 2020
1 parent 1e82285 commit 60ae848
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ _Properties_
- _disableCustomColors_ `boolean`: Whether or not the custom colors are disabled
- _fontSizes_ `Array`: Available font sizes
- _disableCustomFontSizes_ `boolean`: Whether or not the custom font sizes are disabled
- _imageEditing_ `boolean`: Image Editing settings set to false to disable.
- _imageSizes_ `Array`: Available image sizes
- _maxWidth_ `number`: Max width to constraint resizing
- _allowedBlockTypes_ `(boolean|Array)`: Allowed block types
Expand Down
4 changes: 4 additions & 0 deletions packages/block-editor/src/store/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const PREFERENCES_DEFAULTS = {
* @property {boolean} disableCustomColors Whether or not the custom colors are disabled
* @property {Array} fontSizes Available font sizes
* @property {boolean} disableCustomFontSizes Whether or not the custom font sizes are disabled
* @property {boolean} imageEditing Image Editing settings set to false to disable.
* @property {Array} imageSizes Available image sizes
* @property {number} maxWidth Max width to constraint resizing
* @property {boolean|Array} allowedBlockTypes Allowed block types
Expand Down Expand Up @@ -131,6 +132,9 @@ export const SETTINGS_DEFAULTS = {
{ slug: 'full', name: __( 'Full Size' ) },
],

// Allow plugin to disable Image Editor if need be
imageEditing: true,

// This is current max width of the block inner area
// It's used to constraint image resizing and this value could be overridden later by themes
maxWidth: 580,
Expand Down
29 changes: 17 additions & 12 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,22 @@ export default function Image( {
},
[ id, isSelected ]
);
const { maxWidth, isRTL, imageSizes, mediaUpload } = useSelect(
( select ) => {
const { getSettings } = select( 'core/block-editor' );
return pick( getSettings(), [
'imageSizes',
'isRTL',
'maxWidth',
'mediaUpload',
] );
}
);
const {
imageEditing,
imageSizes,
isRTL,
maxWidth,
mediaUpload,
} = useSelect( ( select ) => {
const { getSettings } = select( 'core/block-editor' );
return pick( getSettings(), [
'imageEditing',
'imageSizes',
'isRTL',
'maxWidth',
'mediaUpload',
] );
} );
const { toggleSelection } = useDispatch( 'core/block-editor' );
const { createErrorNotice, createSuccessNotice } = useDispatch(
'core/notices'
Expand Down Expand Up @@ -226,7 +231,7 @@ export default function Image( {
}
}, [ isSelected ] );

const canEditImage = id && naturalWidth && naturalHeight;
const canEditImage = id && naturalWidth && naturalHeight && imageEditing;

const controls = (
<>
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class EditorProvider extends Component {
'gradients',
'hasFixedToolbar',
'hasPermissionsToManageWidgets',
'imageEditing',
'imageSizes',
'imageDimensions',
'isRTL',
Expand Down

0 comments on commit 60ae848

Please sign in to comment.