-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5654e3d
commit f55e063
Showing
5 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { has } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { addFilter } from '@wordpress/hooks'; | ||
import { hasBlockSupport } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Filters registered block settings, extending attributes to include `isSection` and `sectionName`. | ||
* | ||
* @param {Object} settings Original block settings. | ||
* | ||
* @return {Object} Filtered block settings. | ||
*/ | ||
export function addAttribute( settings ) { | ||
if ( hasBlockSupport( settings, '__experimentalSection', false ) ) { | ||
// Allow blocks to specify their own isSection attribute definition with default value if needed. | ||
if ( ! has( settings.attributes, [ 'isSection' ] ) ) { | ||
settings.attributes = { | ||
...settings.attributes, | ||
isSection: { | ||
type: 'boolean', | ||
}, | ||
}; | ||
} | ||
|
||
// Allow blocks to specify their own sectionName attribute definition with default value if needed. | ||
if ( ! has( settings.attributes, [ 'sectionName' ] ) ) { | ||
settings.attributes = { | ||
...settings.attributes, | ||
sectionName: { | ||
type: 'string', | ||
}, | ||
}; | ||
} | ||
} | ||
return settings; | ||
} | ||
|
||
addFilter( | ||
'blocks.registerBlockType', | ||
'core/sections/addAttribute', | ||
addAttribute | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters