Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/wp-includes/block-bindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ function get_block_bindings_source( string $source_name ) {
*
* @since 6.9.0
* @since 7.1.0 Added support for the List Item block.
* @since 7.1.0 Added support for the Icon block.
*
* @param string $block_type The block type whose supported attributes are being retrieved.
* @return array The list of block attributes that are supported by block bindings.
Expand All @@ -149,6 +150,7 @@ function get_block_bindings_supported_attributes( $block_type ) {
'core/post-date' => array( 'datetime' ),
'core/navigation-link' => array( 'url' ),
'core/navigation-submenu' => array( 'url' ),
'core/icon' => array( 'icon' ),
Comment thread
yashjawale marked this conversation as resolved.
Comment thread
yashjawale marked this conversation as resolved.
);

$supported_block_attributes =
Expand Down
65 changes: 65 additions & 0 deletions tests/phpunit/tests/block-bindings/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,71 @@ public function test_update_block_with_value_from_source_image_placeholder() {
);
}

/**
* Tests if the Icon block's icon attribute is updated with the value
* returned by a block bindings source.
*
* @ticket 65725
*
* @covers ::register_block_bindings_source
*/
public function test_update_icon_block_with_value_from_source() {
$get_value_callback = function () {
return 'test-icons/test-icon';
};

wp_register_icon_collection(
'test-icons',
array( 'label' => 'Test Icons' )
);

wp_register_icon(
'test-icons/test-icon',
array(
'label' => 'Test Icon',
'content' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="currentColor"/></svg>',
)
);

register_block_bindings_source(
self::SOURCE_NAME,
array(
'label' => self::SOURCE_LABEL,
'get_value_callback' => $get_value_callback,
)
);

try {
$block_content = <<<HTML
<!-- wp:icon {"metadata":{"bindings":{"icon":{"source":"test/source"}}}} -->
<div class="wp-block-icon"></div>
<!-- /wp:icon -->
HTML;
$parsed_blocks = parse_blocks( $block_content );
$block = new WP_Block( $parsed_blocks[0] );
$result = $block->render();

$this->assertSame(
'test-icons/test-icon',
$block->attributes['icon'],
"The 'icon' attribute should be updated with the value returned by the source."
);
$this->assertStringContainsString(
'<svg',
$result,
'The rendered output should contain an SVG element.'
);
$this->assertStringContainsString(
'wp-block-icon',
$result,
'The rendered output should contain the wp-block-icon class.'
);
} finally {
wp_unregister_icon( 'test-icons/test-icon' );
wp_unregister_icon_collection( 'test-icons' );
}
}

/**
* Tests if the `__default` attribute is replaced with real attributes for
* pattern overrides.
Expand Down
Loading