-
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.
Make the PHP implementation of the replacement of default attributes …
…more generic (not implemented in the pattern block)
- Loading branch information
Showing
3 changed files
with
44 additions
and
36 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,43 @@ | ||
<?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' ] ) && | ||
Check failure on line 26 in lib/compat/wordpress-6.6/blocks.php GitHub Actions / PHP coding standards
|
||
$bindings[ '__default' ][ 'source' ] === 'core/pattern-overrides' | ||
Check failure on line 27 in lib/compat/wordpress-6.6/blocks.php GitHub Actions / PHP coding standards
Check failure on line 27 in lib/compat/wordpress-6.6/blocks.php GitHub Actions / PHP coding standards
|
||
) { | ||
// Build an binding array of all supported attributes. | ||
foreach ( $supported_block_attrs[ $parsed_block['blockName'] ] as $attribute_name ) { | ||
$bindings[ $attribute_name ] = array( 'source' => 'core/pattern-overrides' ); | ||
} | ||
// Merge this into the parsed block's bindings & avoid overwriting existing bindings. | ||
$parsed_block['attrs']['metadata']['bindings'] = array_merge( | ||
$bindings, | ||
$parsed_block['attrs']['metadata']['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