Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor block registration processing to use new properties
  • Loading branch information
gziolo committed Sep 13, 2022
commit d56a0613de2767bf24ebe8597025901bab654085
26 changes: 13 additions & 13 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,15 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
}

$script_fields = array(
'editorScript' => 'editor_script',
'script' => 'script',
'viewScript' => 'view_script',
'editorScript' => 'editor_script_handles',
'script' => 'script_handles',
'viewScript' => 'view_script_handles',
);
foreach ( $script_fields as $metadata_field_name => $settings_field_name ) {
if ( ! empty( $metadata[ $metadata_field_name ] ) ) {
$scripts = $metadata[ $metadata_field_name ];
$scripts = $metadata[ $metadata_field_name ];
$processed_scripts = array();
if ( is_array( $scripts ) ) {
$processed_scripts = array();
for ( $index = 0; $index < count( $scripts ); $index++ ) {
$result = register_block_script_handle(
$metadata,
Expand All @@ -361,28 +361,28 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
$processed_scripts[] = $result;
}
}
$settings[ $settings_field_name ] = $processed_scripts;
} else {
$result = register_block_script_handle(
$metadata,
$metadata_field_name
);
if ( $result ) {
$settings[ $settings_field_name ] = $result;
$processed_scripts[] = $result;
}
}
$settings[ $settings_field_name ] = $processed_scripts;
}
}

$style_fields = array(
'editorStyle' => 'editor_style',
'style' => 'style',
'editorStyle' => 'editor_style_handles',
'style' => 'style_handles',
);
foreach ( $style_fields as $metadata_field_name => $settings_field_name ) {
if ( ! empty( $metadata[ $metadata_field_name ] ) ) {
$styles = $metadata[ $metadata_field_name ];
$styles = $metadata[ $metadata_field_name ];
$processed_styles = array();
if ( is_array( $styles ) ) {
$processed_styles = array();
for ( $index = 0; $index < count( $styles ); $index++ ) {
$result = register_block_style_handle(
$metadata,
Expand All @@ -393,16 +393,16 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
$processed_styles[] = $result;
}
}
$settings[ $settings_field_name ] = $processed_styles;
} else {
$result = register_block_style_handle(
$metadata,
$metadata_field_name
);
if ( $result ) {
$settings[ $settings_field_name ] = $result;
$processed_styles[] = $result;
}
}
$settings[ $settings_field_name ] = $processed_styles;
}
}

Expand Down
19 changes: 14 additions & 5 deletions tests/phpunit/tests/blocks/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,16 +494,25 @@ public function test_block_registers_with_metadata_fixture() {
),
$result->example
);
$this->assertSame( 'tests-notice-editor-script', $result->editor_script );
$this->assertSame( 'tests-notice-script', $result->script );
$this->assertSameSets(
array( 'tests-notice-editor-script' ),
$result->editor_script_handles
);
$this->assertSameSets(
array( 'tests-notice-script' ),
$result->script_handles
);
$this->assertSameSets(
array( 'tests-notice-view-script', 'tests-notice-view-script-2' ),
$result->view_script
$result->view_script_handles
);
$this->assertSameSets(
array( 'tests-notice-editor-style' ),
$result->editor_style_handles
);
$this->assertSame( 'tests-notice-editor-style', $result->editor_style );
$this->assertSameSets(
array( 'tests-notice-style', 'tests-notice-style-2' ),
$result->style
$result->style_handles
);

// @ticket 50328
Expand Down
16 changes: 8 additions & 8 deletions tests/phpunit/tests/rest-api/rest-block-type-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ public function test_get_item_invalid() {
$this->assertFalse( $data['is_dynamic'] );
$this->assertSameSets( array( array() ), $data['variations'] );
// Deprecated properties.
$this->assertNull( $data['editor_script'] );
$this->assertNull( $data['script'] );
$this->assertNull( $data['view_script'] );
$this->assertNull( $data['editor_style'] );
$this->assertNull( $data['style'] );
$this->assertNull( $data['editor_script'] );
$this->assertNull( $data['script'] );
$this->assertNull( $data['view_script'] );
$this->assertNull( $data['editor_style'] );
$this->assertNull( $data['style'] );

}

Expand Down Expand Up @@ -333,9 +333,9 @@ public function test_get_item_defaults() {
// Deprecated properties.
$this->assertNull( $data['editor_script'] );
$this->assertNull( $data['script'] );
$this->assertNull( $data['view_script'] );
$this->assertNull( $data['editor_style'] );
$this->assertNull( $data['style'] );
$this->assertNull( $data['view_script'] );
$this->assertNull( $data['editor_style'] );
$this->assertNull( $data['style'] );
}

public function test_get_variation() {
Expand Down