Make WordPress Core

Changeset 58413


Ignore:
Timestamp:
06/14/2024 09:03:40 AM (9 months ago)
Author:
oandregal
Message:

Section styles: add slug to override non-kebab-cased variations.

Props aaronrobertshaw, oandregal.
Fixes #61440.

Location:
trunk
Files:
1 added
4 edited

Legend:

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

    r58394 r58413  
    250250         * need to have their name set to the kebab case version of their title.
    251251         */
    252         $variation_name = $have_named_variations ? $key : _wp_to_kebab_case( $variation['title'] );
     252        $variation_name = $have_named_variations ? $key : ( $variation['slug'] ?? _wp_to_kebab_case( $variation['title'] ) );
    253253
    254254        foreach ( $supported_blocks as $block_type ) {
     
    442442         * need to have their name set to the kebab case version of their title.
    443443         */
    444         $variation_name  = $have_named_variations ? $key : _wp_to_kebab_case( $variation['title'] );
     444        $variation_name  = $have_named_variations ? $key : ( $variation['slug'] ?? _wp_to_kebab_case( $variation['title'] ) );
    445445        $variation_label = $variation['title'] ?? $variation_name;
    446446
  • trunk/src/wp-includes/class-wp-theme-json.php

    r58409 r58413  
    359359        'patterns',
    360360        'settings',
     361        'slug',
    361362        'styles',
    362363        'templateParts',
     
    32453246     * @since 6.6.0 Updated to allow variation element styles and $origin parameter.
    32463247     *
    3247      * @param array $theme_json Structure to sanitize.
     3248     * @param array  $theme_json Structure to sanitize.
    32483249     * @param string $origin    Optional. What source of data this object represents.
    32493250     *                          One of 'blocks', 'default', 'theme', or 'custom'. Default 'theme'.
  • trunk/tests/phpunit/tests/block-supports/block-style-variations.php

    r58394 r58413  
    6262     *
    6363     * @ticket 61312
     64     * @ticket 61440
    6465     */
    6566    public function test_add_registered_block_styles_to_theme_data() {
     
    99100        );
    100101
     102        /*
     103         * This style is to be deliberately overwritten by the theme.json partial
     104         * See `tests/phpunit/data/themedir1/block-theme/styles/block-style-variation-with-slug.json`.
     105         */
     106        register_block_style(
     107            'core/group',
     108            array(
     109                'name'       => 'WithSlug',
     110                'style_data' => array(
     111                    'color' => array(
     112                        'background' => 'whitesmoke',
     113                        'text'       => 'black',
     114                    ),
     115                ),
     116            )
     117        );
    101118        register_block_style(
    102119            'core/group',
     
    111128        $expected     = array(
    112129            'variations' => array(
     130                // @ticket 61440
     131                'WithSlug'                => array(
     132                    'color' => array(
     133                        'background' => 'aliceblue',
     134                        'text'       => 'midnightblue',
     135                    ),
     136                ),
    113137                'my-variation'            => $variation_styles_data,
    114138
     
    134158
    135159        unregister_block_style( 'core/group', 'my-variation' );
     160        unregister_block_style( 'core/group', 'WithSlug' );
    136161
    137         $this->assertSameSetsWithIndex( $group_styles, $expected );
     162        $this->assertSameSetsWithIndex( $expected, $group_styles );
    138163    }
    139164}
  • trunk/tests/phpunit/tests/theme/wpThemeJsonResolver.php

    r58264 r58413  
    11611161                        ),
    11621162                    ),
     1163                    // @ticket 61440
     1164                    array(
     1165                        'blockTypes' => array( 'core/group', 'core/columns' ),
     1166                        'version'    => 3,
     1167                        'slug'       => 'WithSlug',
     1168                        'title'      => 'With Slug',
     1169                        'styles'     => array(
     1170                            'color' => array(
     1171                                'background' => 'aliceblue',
     1172                                'text'       => 'midnightblue',
     1173                            ),
     1174                        ),
     1175                    ),
    11631176                ),
    11641177            ),
Note: See TracChangeset for help on using the changeset viewer.