-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert blocks that are an alias block into their canonical block
- Loading branch information
1 parent
613c05e
commit 01ea4bb
Showing
3 changed files
with
59 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Convert alias blocks to their canonical form. This function is used | ||
* both in the parser level for previous content and to convert such blocks | ||
* used in Custom Post Types templates. | ||
* | ||
* @param {string} name The block's name | ||
* @param {Object} attributes The block's attributes | ||
* | ||
* @return {[string, Object]} The block's name and attributes, changed accordingly if a match was found | ||
*/ | ||
export function convertAliasBlockNameAndAttributes( name, attributes ) { | ||
const canonicalBlockName = attributes.metadata?.alias; | ||
let blockName = name; | ||
const newAttributes = { ...attributes }; | ||
if ( canonicalBlockName ) { | ||
blockName = canonicalBlockName; | ||
newAttributes.metadata.alias = name; | ||
} | ||
|
||
return [ blockName, newAttributes ]; | ||
} |
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