Skip to content

Commit b34d875

Browse files
committed
Add comments to the server side rendering functions.
1 parent 1b83689 commit b34d875

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

packages/block-library/src/accordion-group/index.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
*
1111
* @return string Returns the updated markup.
1212
*/
13-
1413
function render_block_core_accordion_group( $attributes, $content ) {
1514
if ( ! $content ) {
1615
return $content;
@@ -45,10 +44,18 @@ function render_block_core_accordion_group( $attributes, $content ) {
4544
return $content;
4645
}
4746

47+
/**
48+
* Returns the existing list of ids, or adds a new id to the list.
49+
*
50+
* @since 6.6.0
51+
*
52+
* @param string $id The id of the accordion item.
53+
* @return array|void Returns the ids for the or nothing.
54+
*/
4855
function block_core_accordion_group_item_ids( $id = null ) {
4956
static $ids = array();
5057
if ( null === $id ) {
51-
// Returns the ids and reset them for the next accordion group.
58+
// Returns the ids and resets them for the next accordion group.
5259
$current_ids = $ids;
5360
$ids = array();
5461
return $current_ids;

packages/block-library/src/accordion-item/index.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ function block_core_accordion_item_render( $attributes, $content ) {
1919
$p = new WP_HTML_Tag_Processor( $content );
2020
$unique_id = wp_unique_id( 'accordion-item-' );
2121

22-
// Adds the id to the current accordion group list.
22+
// If the item is open by default,
23+
// add its id to the accordion group's initial context.isOpen list.
2324
if ( $attributes['openByDefault'] ) {
2425
// phpcs:ignore Gutenberg.CodeAnalysis.ForbiddenFunctionsAndClasses.ForbiddenFunctionCall
2526
gutenberg_block_core_accordion_group_item_ids( $unique_id );
2627
}
2728

29+
// Initialize the state of the item on the server using a closure,
30+
// since we need to get derived state based on the current context.
2831
wp_interactivity_state(
2932
'core/accordion',
3033
array(
@@ -43,14 +46,14 @@ function block_core_accordion_item_render( $attributes, $content ) {
4346
$p->set_attribute( 'data-wp-on--click', 'actions.toggle' );
4447
$p->set_attribute( 'aria-controls', $unique_id );
4548
$p->set_attribute( 'data-wp-bind--aria-expanded', 'state.isOpen' );
46-
}
4749

48-
if ( $p->next_tag( array( 'class_name' => 'wp-block-accordion-content' ) ) ) {
49-
$p->set_attribute( 'aria-labelledby', $unique_id );
50-
$p->set_attribute( 'data-wp-bind--aria-hidden', '!state.isOpen' );
50+
if ( $p->next_tag( array( 'class_name' => 'wp-block-accordion-content' ) ) ) {
51+
$p->set_attribute( 'aria-labelledby', $unique_id );
52+
$p->set_attribute( 'data-wp-bind--aria-hidden', '!state.isOpen' );
5153

52-
// Only modify content if all directives have been set.
53-
$content = $p->get_updated_html();
54+
// Only modify content if all directives have been set.
55+
$content = $p->get_updated_html();
56+
}
5457
}
5558
}
5659

0 commit comments

Comments
 (0)