mirror of
git://develop.git.wordpress.org/
synced 2025-04-07 21:53:21 +02:00
Editor: Default attribute value not used with get_block_wrapper_attributes
Ensures that the default values defined in the schema for block attributes are used when rendering the output of the block with `get_block_wrapper_attributes` helper. Props gziolo, jonsurrell, youknowriad, ryelle. Fixes #62114. git-svn-id: https://develop.svn.wordpress.org/trunk@59093 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
b071c28f8b
commit
7d0e751ffb
@ -104,7 +104,7 @@ class WP_Block_Supports {
|
||||
}
|
||||
|
||||
$block_attributes = array_key_exists( 'attrs', self::$block_to_render ) && is_array( self::$block_to_render['attrs'] )
|
||||
? self::$block_to_render['attrs']
|
||||
? $block_type->prepare_attributes_for_render( self::$block_to_render['attrs'] )
|
||||
: array();
|
||||
|
||||
$output = array();
|
||||
|
@ -286,6 +286,56 @@ class Tests_Blocks_Render extends WP_UnitTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 62114
|
||||
*/
|
||||
public function test_dynamic_block_with_default_attributes() {
|
||||
$settings = array(
|
||||
'attributes' => array(
|
||||
'content' => array(
|
||||
'type' => 'string',
|
||||
'default' => 'Default content.',
|
||||
),
|
||||
'align' => array(
|
||||
'type' => 'string',
|
||||
'default' => 'full',
|
||||
),
|
||||
'backgroundColor' => array(
|
||||
'type' => 'string',
|
||||
'default' => 'blueberry-1',
|
||||
),
|
||||
'textColor' => array(
|
||||
'type' => 'string',
|
||||
'default' => 'white',
|
||||
),
|
||||
),
|
||||
'supports' => array(
|
||||
'align' => array( 'wide', 'full' ),
|
||||
'color' => array(
|
||||
'background' => true,
|
||||
'text' => true,
|
||||
),
|
||||
),
|
||||
'render_callback' => function ( $attributes ) {
|
||||
return '<p ' . get_block_wrapper_attributes() . '>' . $attributes['content'] . '</p>';
|
||||
},
|
||||
);
|
||||
register_block_type( 'core/dynamic', $settings );
|
||||
|
||||
$post_content =
|
||||
'before' .
|
||||
'<!-- wp:core/dynamic --><!-- /wp:core/dynamic -->' .
|
||||
'after';
|
||||
|
||||
$updated_post_content = do_blocks( $post_content );
|
||||
$this->assertSame(
|
||||
$updated_post_content,
|
||||
'before' .
|
||||
'<p class="alignfull wp-block-dynamic has-text-color has-white-color has-background has-blueberry-1-background-color">Default content.</p>' .
|
||||
'after'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 45109
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user