Skip to content

Commit

Permalink
Fixes WordPress#11949: Error: The block xxx can have a maximum of 3 k…
Browse files Browse the repository at this point in the history
…eywords.
  • Loading branch information
jameelmoses committed Feb 5, 2019
1 parent da3dfcc commit 98cea21
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
22 changes: 11 additions & 11 deletions docs/block-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ icon: {

* **Type:** `Array`

Sometimes a block could have aliases that help users discover it while searching. For example, an `image` block could also want to be discovered by `photo`. You can do so by providing an array of terms (which can be translated). It is only allowed to add as much as three terms per block.
Sometimes a block could have aliases that help users discover it while searching. For example, an `image` block could also want to be discovered by `photo`. You can do so by providing an array of terms (which can be translated).

```js
// Make it easier to discover a block with keyword aliases.
Expand All @@ -124,18 +124,18 @@ Block styles can be used to provide alternative styles to block. It works by add
// Register block styles.
styles: [
// Mark style as default.
{
name: 'default',
label: __( 'Rounded' ),
isDefault: true
{
name: 'default',
label: __( 'Rounded' ),
isDefault: true
},
{
name: 'outline',
label: __( 'Outline' )
{
name: 'outline',
label: __( 'Outline' )
},
{
name: 'squared',
label: __( 'Squared' )
{
name: 'squared',
label: __( 'Squared' )
},
],
```
Expand Down
9 changes: 1 addition & 8 deletions packages/blocks/src/api/registration.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint no-console: [ 'error', { allow: [ 'error', 'warn' ] } ] */
/* eslint no-console: [ 'error', { allow: [ 'error' ] } ] */

/**
* External dependencies
Expand Down Expand Up @@ -140,13 +140,6 @@ export function registerBlockType( name, settings ) {
return;
}

if ( 'keywords' in settings && settings.keywords.length > 3 ) {
console.warn(
'The block "' + name + '" can have a maximum of 3 keywords.'
);
settings.keywords = settings.keywords.slice( 0, 3 );
}

dispatch( 'core/blocks' ).addBlockTypes( settings );

return settings;
Expand Down
7 changes: 0 additions & 7 deletions packages/blocks/src/api/test/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,6 @@ describe( 'blocks', () => {
expect( block ).toBeUndefined();
} );

it( 'should reject blocks with more than 3 keywords', () => {
const blockType = { save: noop, keywords: [ 'apple', 'orange', 'lemon', 'pineapple' ], category: 'common', title: 'block title' },
block = registerBlockType( 'my-plugin/fancy-block-7', blockType );
expect( console ).toHaveErroredWith( 'The block "my-plugin/fancy-block-7" can have a maximum of 3 keywords.' );
expect( block ).toBeUndefined();
} );

it( 'should reject blocks without category', () => {
const blockType = { settingName: 'settingValue', save: noop, title: 'block title' },
block = registerBlockType( 'my-plugin/fancy-block-8', blockType );
Expand Down

0 comments on commit 98cea21

Please sign in to comment.