Skip to content

Commit

Permalink
Add comments to the server side rendering functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jffng committed Aug 6, 2024
1 parent 1b83689 commit b34d875
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
11 changes: 9 additions & 2 deletions packages/block-library/src/accordion-group/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*
* @return string Returns the updated markup.
*/

function render_block_core_accordion_group( $attributes, $content ) {
if ( ! $content ) {
return $content;
Expand Down Expand Up @@ -45,10 +44,18 @@ function render_block_core_accordion_group( $attributes, $content ) {
return $content;
}

/**
* Returns the existing list of ids, or adds a new id to the list.
*
* @since 6.6.0
*
* @param string $id The id of the accordion item.
* @return array|void Returns the ids for the or nothing.
*/
function block_core_accordion_group_item_ids( $id = null ) {
static $ids = array();
if ( null === $id ) {
// Returns the ids and reset them for the next accordion group.
// Returns the ids and resets them for the next accordion group.
$current_ids = $ids;
$ids = array();
return $current_ids;
Expand Down
17 changes: 10 additions & 7 deletions packages/block-library/src/accordion-item/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ function block_core_accordion_item_render( $attributes, $content ) {
$p = new WP_HTML_Tag_Processor( $content );
$unique_id = wp_unique_id( 'accordion-item-' );

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

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

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

// Only modify content if all directives have been set.
$content = $p->get_updated_html();
// Only modify content if all directives have been set.
$content = $p->get_updated_html();
}
}
}

Expand Down

0 comments on commit b34d875

Please sign in to comment.