-
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.
Navigation Link: populate variation types like post link, page link, …
…category link in server from register_block_type_from_metadata instead of hardcoded file.
- Loading branch information
Showing
6 changed files
with
116 additions
and
66 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 |
---|---|---|
|
@@ -28,6 +28,9 @@ | |
}, | ||
"title": { | ||
"type": "string" | ||
}, | ||
"kind": { | ||
"type": "string" | ||
} | ||
}, | ||
"usesContext": [ | ||
|
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,49 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { addFilter } from '@wordpress/hooks'; | ||
import { category, page, postTitle, tag } from '@wordpress/icons'; | ||
|
||
const ICON_MAP = { | ||
category, | ||
page, | ||
post: postTitle, | ||
tag, | ||
//TODO: add a generic CPT icon, remember to ask folks for a new icon | ||
}; | ||
|
||
function enhanceNavigationLinkVariations( settings, name ) { | ||
if ( name !== 'core/navigation-link' ) { | ||
return settings; | ||
} | ||
|
||
if ( settings?.variations ) { | ||
const variations = settings.variations.map( ( variation ) => { | ||
return { | ||
...variation, | ||
...( ! variation.icon && | ||
ICON_MAP[ variation.name ] && { | ||
icon: ICON_MAP[ variation.name ], | ||
} ), | ||
...( ! variation.isActive && { | ||
isActive: ( blockAttributes, variationAttributes ) => { | ||
return ( | ||
blockAttributes.type === variationAttributes.type | ||
); | ||
}, | ||
} ), | ||
}; | ||
} ); | ||
return { | ||
...settings, | ||
variations, | ||
}; | ||
} | ||
return settings; | ||
} | ||
|
||
addFilter( | ||
'blocks.registerBlockType', | ||
'core/navigation-link', | ||
enhanceNavigationLinkVariations | ||
); |
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 was deleted.
Oops, something went wrong.