REST API: Remove assets field from block directory controller.

Gutenberg no longer uses the assets field to fetch the assets for the installed block so this field can be dropped from the endpoint. This allows us to reintroduce it at a later point without needing to worry about backward compatibility.

See #50732.


git-svn-id: https://develop.svn.wordpress.org/trunk@48656 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Timothy Jacobs 2020-07-28 04:08:56 +00:00
parent 5bb5053127
commit b29101aca0
2 changed files with 1 additions and 34 deletions

View File

@ -129,7 +129,6 @@ class WP_REST_Block_Directory_Controller extends WP_REST_Controller {
'author_block_count' => intval( $plugin['author_block_count'] ),
'author' => wp_strip_all_tags( $plugin['author'] ),
'icon' => ( isset( $plugin['icons']['1x'] ) ? $plugin['icons']['1x'] : 'block-default' ),
'assets' => array(),
'last_updated' => gmdate( 'Y-m-d\TH:i:s', strtotime( $plugin['last_updated'] ) ),
'humanized_updated' => sprintf(
/* translators: %s: Human-readable time difference. */
@ -138,21 +137,6 @@ class WP_REST_Block_Directory_Controller extends WP_REST_Controller {
),
);
foreach ( $plugin['block_assets'] as $asset ) {
// Allow for fully qualified URLs in future
if ( 'https' === wp_parse_url( $asset, PHP_URL_SCHEME ) && ! empty( wp_parse_url( $asset, PHP_URL_HOST ) ) ) {
$block['assets'][] = esc_url_raw(
$asset,
array( 'https' )
);
} else {
$block['assets'][] = esc_url_raw(
add_query_arg( 'v', strtotime( $block['last_updated'] ), 'https://ps.w.org/' . $plugin['slug'] . $asset ),
array( 'https' )
);
}
}
$this->add_additional_fields_to_object( $block, $request );
$response = new WP_REST_Response( $block );
@ -296,16 +280,6 @@ class WP_REST_Block_Directory_Controller extends WP_REST_Controller {
'type' => 'string',
'context' => array( 'view' ),
),
'assets' => array(
'description' => __( 'An object representing the block CSS and JavaScript assets.' ),
'type' => 'array',
'context' => array( 'view' ),
'readonly' => true,
'items' => array(
'type' => 'string',
'format' => 'uri',
),
),
),
);

View File

@ -162,12 +162,6 @@ class WP_REST_Block_Directory_Controller_Test extends WP_Test_REST_Controller_Te
'author_block_count' => 1,
'author' => 'sorta brilliant',
'icon' => 'https://ps.w.org/guidepost/assets/icon-128x128.jpg?rev=2235512',
'assets' => array(
'https://ps.w.org/guidepost/tags/1.2.1/build/index.js?v=1584940380',
'https://ps.w.org/guidepost/tags/1.2.1/build/guidepost-editor.css?v=1584940380',
'https://ps.w.org/guidepost/tags/1.2.1/build/guidepost-style.css?v=1584940380',
'https://ps.w.org/guidepost/tags/1.2.1/build/guidepost-theme.js?v=1584940380',
),
'last_updated' => gmdate( 'Y-m-d\TH:i:s', strtotime( $plugin['last_updated'] ) ),
'humanized_updated' => sprintf( '%s ago', human_time_diff( strtotime( $plugin['last_updated'] ) ) ),
);
@ -192,7 +186,7 @@ class WP_REST_Block_Directory_Controller_Test extends WP_Test_REST_Controller_Te
$properties = $data['schema']['properties'];
$this->assertCount( 14, $properties );
$this->assertCount( 13, $properties );
$this->assertArrayHasKey( 'name', $properties );
$this->assertArrayHasKey( 'title', $properties );
$this->assertArrayHasKey( 'description', $properties );
@ -206,7 +200,6 @@ class WP_REST_Block_Directory_Controller_Test extends WP_Test_REST_Controller_Te
$this->assertArrayHasKey( 'icon', $properties );
$this->assertArrayHasKey( 'last_updated', $properties );
$this->assertArrayHasKey( 'humanized_updated', $properties );
$this->assertArrayHasKey( 'assets', $properties );
}
/**