Make WordPress Core

Changeset 59925


Ignore:
Timestamp:
03/04/2025 01:04:49 PM (6 weeks ago)
Author:
Mamaduka
Message:

Block support: Add server-side processing for ariaLabel.

Adds server-side registration for ariaLabel block support and its required fields. Fully enabling feature support for dynamic blocks and consumers using ServerSideRender component.

Props wildworks, fabiankaegy, joemcgill, poena.
Fixes #62919.

Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-block-supports.php

    r59093 r59925  
    182182    // This is hardcoded on purpose.
    183183    // We only support a fixed list of attributes.
    184     $attributes_to_merge = array( 'style', 'class', 'id' );
     184    $attributes_to_merge = array( 'style', 'class', 'id', 'aria-label' );
    185185    $attributes          = array();
    186186    foreach ( $attributes_to_merge as $attribute_name ) {
  • trunk/src/wp-settings.php

    r59837 r59925  
    388388require ABSPATH . WPINC . '/block-supports/background.php';
    389389require ABSPATH . WPINC . '/block-supports/block-style-variations.php';
     390require ABSPATH . WPINC . '/block-supports/aria-label.php';
    390391require ABSPATH . WPINC . '/style-engine.php';
    391392require ABSPATH . WPINC . '/style-engine/class-wp-style-engine.php';
  • trunk/tests/phpunit/tests/blocks/supportedStyles.php

    r57987 r59925  
    149149            array_map( 'trim', explode( ';', $style_list ) ),
    150150            'Style list does not match expected styles'
     151        );
     152    }
     153
     154    /**
     155     * Runs assertions that the rendered output has expected content and aria-label attr.
     156     *
     157     * @param array  $block               Block to render.
     158     * @param string $expected_aria_label Expected output aria-label attr string.
     159     */
     160    private function assert_content_and_aria_label_match( $block, $expected_aria_label ) {
     161        $styled_block = $this->render_example_block( $block );
     162        $content      = $this->get_content_from_block( $styled_block );
     163
     164        $this->assertSame( self::BLOCK_CONTENT, $content, 'Block content does not match expected content' );
     165        $this->assertSame(
     166            $expected_aria_label,
     167            $this->get_attribute_from_block( 'aria-label', $styled_block ),
     168            'Aria-label does not match expected aria-label'
    151169        );
    152170    }
     
    687705
    688706    /**
     707     * Tests aria-label server-side block support.
     708     */
     709    public function test_aria_label_support() {
     710        $block_type_settings = array(
     711            'attributes' => array(),
     712            'supports'   => array(
     713                'ariaLabel' => true,
     714            ),
     715        );
     716        $this->register_block_type( 'core/example', $block_type_settings );
     717
     718        $block = array(
     719            'blockName'    => 'core/example',
     720            'attrs'        => array(
     721                'ariaLabel' => 'Label',
     722            ),
     723            'innerBlock'   => array(),
     724            'innerContent' => array(),
     725            'innerHTML'    => array(),
     726        );
     727
     728        $this->assert_content_and_aria_label_match( $block, 'Label' );
     729    }
     730
     731    /**
    689732     * Ensures libxml_internal_errors is being used instead of @ warning suppression
    690733     */
Note: See TracChangeset for help on using the changeset viewer.