Skip to content

Commit

Permalink
Rename allowedBlockTypes to parent
Browse files Browse the repository at this point in the history
  • Loading branch information
noisysocks committed May 17, 2018
1 parent 1efb6e5 commit b46ec6b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions docs/block-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,17 @@ A once-only block can be inserted into each post, one time only. For example, th
useOnce: true,
```

#### allowedParentBlocks (optional)
#### parent (optional)

* **Type:** `Array`

Blocks can be inserted into other blocks as nested content. Sometimes it is useful to restrict a block so that it is only available as a nested block. For example, you might want to allow an 'Add to Cart' block to only be available within a 'Product' block.

Setting `allowedParentBlocks` lets a block require that it is only available when nested within the specified blocks.
Setting `parent` lets a block require that it is only available when nested within the specified blocks.

```js
// Only allow this block when it is nested in a Columns block
allowedParentBlocks: [ 'core/columns' ],
parent: [ 'core/columns' ],
```

#### supports (optional)
Expand Down
4 changes: 2 additions & 2 deletions editor/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ export const canInsertBlockType = createSelector(
const parentAllowedBlocks = get( parentBlockListSettings, [ 'supportedBlocks' ] );
const hasParentAllowedBlock = checkAllowList( parentAllowedBlocks, blockName );

const blockAllowedParentBlocks = blockType.allowedParentBlocks;
const blockAllowedParentBlocks = blockType.parent;
const parentName = getBlockName( state, parentUID );
const hasBlockAllowedParent = checkAllowList( blockAllowedParentBlocks, parentName );

Expand Down Expand Up @@ -1389,7 +1389,7 @@ export const getInserterItems = createSelector(
isDisabled = getBlocks( state ).some( ( block ) => block.name === blockType.name );
}

const isContextual = isArray( blockType.allowedParentBlocks );
const isContextual = isArray( blockType.parent );
const { time, count } = getInsertUsage( state, id );

return {
Expand Down
10 changes: 5 additions & 5 deletions editor/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe( 'selectors', () => {
title: 'Test Block C',
icon: 'test',
keywords: [ 'testing' ],
allowedParentBlocks: [ 'core/test-block-b' ],
parent: [ 'core/test-block-b' ],
} );

cachedSelectors = filter( selectors, property( 'clear' ) );
Expand Down Expand Up @@ -2698,7 +2698,7 @@ describe( 'selectors', () => {
expect( canInsertBlockType( state, 'core/test-block-a' ) ).toBe( false );
} );

it( 'should deny blocks that restrict allowedParentBlocks from being inserted into the root', () => {
it( 'should deny blocks that restrict parent from being inserted into the root', () => {
const state = {
editor: {
present: {
Expand All @@ -2711,7 +2711,7 @@ describe( 'selectors', () => {
expect( canInsertBlockType( state, 'core/test-block-c' ) ).toBe( false );
} );

it( 'should deny blocks that restrict allowedParentBlocks from being inserted into a restricted parent', () => {
it( 'should deny blocks that restrict parent from being inserted into a restricted parent', () => {
const state = {
editor: {
present: {
Expand All @@ -2726,7 +2726,7 @@ describe( 'selectors', () => {
expect( canInsertBlockType( state, 'core/test-block-c', 'block1' ) ).toBe( false );
} );

it( 'should allow blocks that restrict allowedParentBlocks to be inserted into an allowed parent', () => {
it( 'should allow blocks that restrict parent to be inserted into an allowed parent', () => {
const state = {
editor: {
present: {
Expand Down Expand Up @@ -2779,7 +2779,7 @@ describe( 'selectors', () => {
expect( canInsertBlockType( state, 'core/test-block-b', 'block1' ) ).toBe( true );
} );

it( 'should prioritise allowedParentBlocks over allowedBlocks', () => {
it( 'should prioritise parent over allowedBlocks', () => {
const state = {
editor: {
present: {
Expand Down

0 comments on commit b46ec6b

Please sign in to comment.