-
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.
Use metadata object attribute (+3 squashed commits)
Squashed commits: [c1bd86cd5d] Use section object [7667d1715e] Add unit test [e7d647eb76] Add: Section concept
- Loading branch information
1 parent
1326a46
commit 871b7ed
Showing
7 changed files
with
90 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
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,40 @@ | ||
/** | ||
* 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 `metadata` in blocks declaring section support. | ||
* | ||
* @param {Object} blockTypeSettings Original block settings. | ||
* | ||
* @return {Object} Filtered block settings. | ||
*/ | ||
export function addAttribute( blockTypeSettings ) { | ||
if ( | ||
hasBlockSupport( blockTypeSettings, '__experimentalMetadata', false ) | ||
) { | ||
// Allow blocks to specify their own metadata attribute definition with default value if needed. | ||
if ( ! has( blockTypeSettings.attributes, [ 'metadata' ] ) ) { | ||
blockTypeSettings.attributes = { | ||
...blockTypeSettings.attributes, | ||
metadata: { | ||
type: 'object', | ||
}, | ||
}; | ||
} | ||
} | ||
return blockTypeSettings; | ||
} | ||
|
||
addFilter( | ||
'blocks.registerBlockType', | ||
'core/metadata/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