forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
__default
binding for pattern overrides (WordPress#60694)
Co-authored-by: kevin940726 <[email protected]> Co-authored-by: talldan <[email protected]> Co-authored-by: mcsf <[email protected]> Co-authored-by: gziolo <[email protected]> Co-authored-by: SantosGuillamot <[email protected]> Co-authored-by: youknowriad <[email protected]>
- Loading branch information
1 parent
596b750
commit 755649e
Showing
11 changed files
with
245 additions
and
74 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,3 @@ | ||
https://github.com/WordPress/wordpress-develop/pull/6694 | ||
|
||
* https://github.com/WordPress/gutenberg/pull/60694 |
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,46 @@ | ||
<?php | ||
/** | ||
* Temporary compatibility shims for block APIs present in Gutenberg. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Replace the `__default` block bindings attribute with the full list of supported | ||
* attribute names for pattern overrides. | ||
* | ||
* @param array $parsed_block The full block, including name and attributes. | ||
* | ||
* @return string The parsed block with default binding replace. | ||
*/ | ||
function gutenberg_replace_pattern_override_default_binding( $parsed_block ) { | ||
$supported_block_attrs = array( | ||
'core/paragraph' => array( 'content' ), | ||
'core/heading' => array( 'content' ), | ||
'core/image' => array( 'id', 'url', 'title', 'alt' ), | ||
'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ), | ||
); | ||
|
||
$bindings = $parsed_block['attrs']['metadata']['bindings'] ?? array(); | ||
if ( | ||
isset( $bindings['__default']['source'] ) && | ||
'core/pattern-overrides' === $bindings['__default']['source'] | ||
) { | ||
$updated_bindings = array(); | ||
|
||
// Build an binding array of all supported attributes. | ||
// Note that this also omits the `__default` attribute from the | ||
// resulting array. | ||
foreach ( $supported_block_attrs[ $parsed_block['blockName'] ] as $attribute_name ) { | ||
// Retain any non-pattern override bindings that might be present. | ||
$updated_bindings[ $attribute_name ] = isset( $bindings[ $attribute_name ] ) | ||
? $bindings[ $attribute_name ] | ||
: array( 'source' => 'core/pattern-overrides' ); | ||
} | ||
$parsed_block['attrs']['metadata']['bindings'] = $updated_bindings; | ||
} | ||
|
||
return $parsed_block; | ||
} | ||
|
||
add_filter( 'render_block_data', 'gutenberg_replace_pattern_override_default_binding', 10, 1 ); |
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
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
Oops, something went wrong.