Skip to content

Commit

Permalink
Blocks: Register block when invalid value provided for the icon (#34350)
Browse files Browse the repository at this point in the history
* Blocks: Register block when invalid value provided for the icon

* Include an entry in the package changelog
  • Loading branch information
gziolo committed Sep 1, 2021
1 parent 6730182 commit 796d25c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 47 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/blocks/CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Backward Compatibility

- Register a block even when an invalid value provided for the icon setting ([#34350](https://github.com/WordPress/gutenberg/pull/34350)).

## 11.0.0 (2021-07-29)

### Breaking Change
Expand Down
1 change: 0 additions & 1 deletion packages/blocks/package.json
Expand Up @@ -40,7 +40,6 @@
"@wordpress/hooks": "file:../hooks",
"@wordpress/html-entities": "file:../html-entities",
"@wordpress/i18n": "file:../i18n",
"@wordpress/icons": "file:../icons",
"@wordpress/is-shallow-equal": "file:../is-shallow-equal",
"@wordpress/shortcode": "file:../shortcode",
"hpq": "^1.3.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/blocks/src/api/constants.js
@@ -1,3 +1,5 @@
export const BLOCK_ICON_DEFAULT = 'block-default';

/**
* Array of valid keys in a block type settings deprecation object.
*
Expand Down
5 changes: 2 additions & 3 deletions packages/blocks/src/api/registration.js
Expand Up @@ -25,14 +25,13 @@ import {
import { applyFilters } from '@wordpress/hooks';
import { select, dispatch } from '@wordpress/data';
import { _x } from '@wordpress/i18n';
import { blockDefault } from '@wordpress/icons';

/**
* Internal dependencies
*/
import i18nBlockSchema from './i18n-block.json';
import { isValidIcon, normalizeIconObject } from './utils';
import { DEPRECATED_ENTRY_KEYS } from './constants';
import { BLOCK_ICON_DEFAULT, DEPRECATED_ENTRY_KEYS } from './constants';
import { store as blocksStore } from '../store';

/**
Expand Down Expand Up @@ -265,7 +264,7 @@ export function registerBlockType( blockNameOrMetadata, settings ) {

settings = {
name,
icon: blockDefault,
icon: BLOCK_ICON_DEFAULT,
keywords: [],
attributes: {},
providesContext: {},
Expand Down
57 changes: 15 additions & 42 deletions packages/blocks/src/api/test/registration.js
Expand Up @@ -10,7 +10,6 @@ import { noop, get, omit, pick } from 'lodash';
*/
import { addFilter, removeAllFilters, removeFilter } from '@wordpress/hooks';
import { select } from '@wordpress/data';
import { blockDefault as blockIcon } from '@wordpress/icons';

/**
* Internal dependencies
Expand All @@ -36,7 +35,7 @@ import {
serverSideBlockDefinitions,
unstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase
} from '../registration';
import { DEPRECATED_ENTRY_KEYS } from '../constants';
import { BLOCK_ICON_DEFAULT, DEPRECATED_ENTRY_KEYS } from '../constants';
import { store as blocksStore } from '../../store';

describe( 'blocks', () => {
Expand Down Expand Up @@ -121,9 +120,7 @@ describe( 'blocks', () => {
expect( console ).not.toHaveErrored();
expect( block ).toEqual( {
name: 'my-plugin/fancy-block-4',
icon: {
src: blockIcon,
},
icon: { src: BLOCK_ICON_DEFAULT },
attributes: {},
providesContext: {},
usesContext: [],
Expand Down Expand Up @@ -268,9 +265,7 @@ describe( 'blocks', () => {
name: 'core/test-block-with-defaults',
title: 'block title',
category: 'text',
icon: {
src: blockIcon,
},
icon: { src: BLOCK_ICON_DEFAULT },
attributes: {},
providesContext: {},
usesContext: [],
Expand Down Expand Up @@ -301,9 +296,7 @@ describe( 'blocks', () => {
save: noop,
category: 'text',
title: 'block title',
icon: {
src: blockIcon,
},
icon: { src: BLOCK_ICON_DEFAULT },
attributes: {
ok: {
type: 'boolean',
Expand Down Expand Up @@ -338,9 +331,7 @@ describe( 'blocks', () => {
name: blockName,
save: expect.any( Function ),
title: 'block title',
icon: {
src: blockIcon,
},
icon: { src: BLOCK_ICON_DEFAULT },
attributes: {},
providesContext: {},
usesContext: [],
Expand Down Expand Up @@ -371,9 +362,7 @@ describe( 'blocks', () => {
name: blockName,
save: expect.any( Function ),
title: 'block title',
icon: {
src: blockIcon,
},
icon: { src: BLOCK_ICON_DEFAULT },
attributes: {},
providesContext: {
fontSize: 'fontSize',
Expand Down Expand Up @@ -410,9 +399,7 @@ describe( 'blocks', () => {
save: expect.any( Function ),
title: 'block title',
category: 'widgets',
icon: {
src: blockIcon,
},
icon: { src: BLOCK_ICON_DEFAULT },
attributes: {},
providesContext: {},
usesContext: [],
Expand Down Expand Up @@ -636,9 +623,7 @@ describe( 'blocks', () => {
save: noop,
category: 'text',
title: 'block title',
icon: {
src: blockIcon,
},
icon: { src: BLOCK_ICON_DEFAULT },
attributes: {},
providesContext: {},
usesContext: [],
Expand Down Expand Up @@ -723,7 +708,7 @@ describe( 'blocks', () => {
...omit(
{
name,
icon: blockIcon,
icon: BLOCK_ICON_DEFAULT,
attributes: {},
providesContext: {},
usesContext: [],
Expand Down Expand Up @@ -960,9 +945,7 @@ describe( 'blocks', () => {
save: noop,
category: 'text',
title: 'block title',
icon: {
src: blockIcon,
},
icon: { src: BLOCK_ICON_DEFAULT },
attributes: {},
providesContext: {},
usesContext: [],
Expand All @@ -979,9 +962,7 @@ describe( 'blocks', () => {
save: noop,
category: 'text',
title: 'block title',
icon: {
src: blockIcon,
},
icon: { src: BLOCK_ICON_DEFAULT },
attributes: {},
providesContext: {},
usesContext: [],
Expand Down Expand Up @@ -1059,9 +1040,7 @@ describe( 'blocks', () => {
save: noop,
category: 'text',
title: 'block title',
icon: {
src: blockIcon,
},
icon: { src: BLOCK_ICON_DEFAULT },
attributes: {},
providesContext: {},
usesContext: [],
Expand All @@ -1085,9 +1064,7 @@ describe( 'blocks', () => {
save: noop,
category: 'text',
title: 'block title',
icon: {
src: blockIcon,
},
icon: { src: BLOCK_ICON_DEFAULT },
attributes: {},
providesContext: {},
usesContext: [],
Expand Down Expand Up @@ -1118,9 +1095,7 @@ describe( 'blocks', () => {
save: noop,
category: 'text',
title: 'block title',
icon: {
src: blockIcon,
},
icon: { src: BLOCK_ICON_DEFAULT },
attributes: {},
providesContext: {},
usesContext: [],
Expand All @@ -1135,9 +1110,7 @@ describe( 'blocks', () => {
save: noop,
category: 'text',
title: 'block title',
icon: {
src: blockIcon,
},
icon: { src: BLOCK_ICON_DEFAULT },
attributes: {},
providesContext: {},
usesContext: [],
Expand Down
2 changes: 2 additions & 0 deletions packages/blocks/src/api/utils.js
Expand Up @@ -14,6 +14,7 @@ import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
/**
* Internal dependencies
*/
import { BLOCK_ICON_DEFAULT } from './constants';
import { getBlockType, getDefaultBlockName } from './registration';
import { createBlock } from './factory';

Expand Down Expand Up @@ -89,6 +90,7 @@ export function isValidIcon( icon ) {
* @return {WPBlockTypeIconDescriptor} Object describing the icon.
*/
export function normalizeIconObject( icon ) {
icon = icon || BLOCK_ICON_DEFAULT;
if ( isValidIcon( icon ) ) {
return { src: icon };
}
Expand Down

0 comments on commit 796d25c

Please sign in to comment.