Make WordPress Core


Ignore:
Timestamp:
08/11/2021 09:06:31 AM (3 years ago)
Author:
gziolo
Message:

Blocks: Add support for variations in block.json` file

We integrated variations with block types and the corresponding REST API endpoint in #52688. It's a follow-up patch to add missing support to the block.json metadata file when using register_block_type.

Some fields for variations are translatable.Therefore, i18n schema was copied over from Gutenberg: https://github.com/WordPress/gutenberg/blob/trunk/packages/blocks/src/api/i18n-block.json. The accompanying implementation was adapted as translate_settings_using_i18n_schema.

Props: gwwar, swissspidy, schlessera, jorgefilipecosta.
Fixes #53238.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/blocks/register.php

    r51568 r51599  
    6868
    6969        parent::tear_down();
     70    }
     71
     72    /**
     73     * Returns Polish locale string.
     74     *
     75     * @return string
     76     */
     77    function filter_set_locale_to_polish() {
     78        return 'pl_PL';
    7079    }
    7180
     
    373382        $this->assertSame(
    374383            array(
     384                array(
     385                    'name'        => 'error',
     386                    'title'       => 'Error',
     387                    'description' => 'Shows error.',
     388                    'keywords'    => array( 'failure' ),
     389                ),
     390            ),
     391            $result->variations
     392        );
     393        $this->assertSame(
     394            array(
    375395                'attributes' => array(
    376396                    'message' => 'This is a notice!',
     
    408428     */
    409429    function test_block_registers_with_metadata_i18n_support() {
    410         function filter_set_locale_to_polish() {
    411             return 'pl_PL';
    412         }
    413         add_filter( 'locale', 'filter_set_locale_to_polish' );
     430        add_filter( 'locale', array( $this, 'filter_set_locale_to_polish' ) );
    414431        load_textdomain( 'notice', WP_LANG_DIR . '/plugins/notice-pl_PL.mo' );
    415432
     
    419436
    420437        unload_textdomain( 'notice' );
    421         remove_filter( 'locale', 'filter_set_locale_to_polish' );
     438        remove_filter( 'locale', array( $this, 'filter_set_locale_to_polish' ) );
    422439
    423440        $this->assertInstanceOf( 'WP_Block_Type', $result );
     
    440457            $result->styles
    441458        );
     459        $this->assertSame(
     460            array(
     461                array(
     462                    'name'        => 'error',
     463                    'title'       => 'Błąd',
     464                    'description' => 'Wyświetla błąd.',
     465                    'keywords'    => array( 'niepowodzenie' ),
     466                ),
     467            ),
     468            $result->variations
     469        );
    442470    }
    443471
Note: See TracChangeset for help on using the changeset viewer.