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

Image: Add the ability for a plugin to disable Image Editor #23966

Merged
merged 3 commits into from Jul 20, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/block-editor/README.md
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
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
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
Expand Up @@ -140,6 +140,7 @@ class EditorProvider extends Component {
'gradients',
'hasFixedToolbar',
'hasPermissionsToManageWidgets',
'imageEditing',
'imageSizes',
'imageDimensions',
'isRTL',
Expand Down