Skip to content

Commit

Permalink
Fix hacky block editor settings filter
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed Aug 23, 2024
1 parent d5d2667 commit b74ae21
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
25 changes: 8 additions & 17 deletions lib/experimental/block-editor-settings-mobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,15 @@
* @return array New block editor settings.
*/
function gutenberg_get_block_editor_settings_mobile( $settings ) {
if (
defined( 'REST_REQUEST' ) &&
REST_REQUEST &&
isset( $_GET['context'] ) &&
'mobile' === $_GET['context']
) {
if ( wp_theme_has_theme_json() ) {
$settings['__experimentalStyles'] = gutenberg_get_global_styles();
}

// To tell mobile that the site uses quote v2 (inner blocks).
// See https://github.com/WordPress/gutenberg/pull/25892.
$settings['__experimentalEnableQuoteBlockV2'] = true;
// To tell mobile that the site uses list v2 (inner blocks).
$settings['__experimentalEnableListBlockV2'] = true;
if ( wp_theme_has_theme_json() ) {
$settings['__experimentalStyles'] = gutenberg_get_global_styles();
}

// To tell mobile that the site uses quote v2 (inner blocks).
// See https://github.com/WordPress/gutenberg/pull/25892.
$settings['__experimentalEnableQuoteBlockV2'] = true;
// To tell mobile that the site uses list v2 (inner blocks).
$settings['__experimentalEnableListBlockV2'] = true;

return $settings;
}

add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings_mobile', PHP_INT_MAX );
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,14 @@ public function get_items( $request ) { // phpcs:ignore VariableAnalysis.CodeAna
break;
}

Check failure on line 95 in lib/experimental/class-wp-rest-block-editor-settings-controller.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Functions must not contain multiple empty lines in a row; found 2 empty lines

add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings_mobile', PHP_INT_MAX );

$editor_context = new WP_Block_Editor_Context( array( 'name' => $editor_context_name ) );
$settings = get_block_editor_settings( array(), $editor_context );

remove_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings_mobile', PHP_INT_MAX );

return rest_ensure_response( $settings );
}

Expand Down
8 changes: 1 addition & 7 deletions phpunit/experimental/block-editor-settings-mobile-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
*
* @covers WP_REST_Block_Editor_Settings_Controller
*/

if ( ! defined( 'REST_REQUEST' ) ) {
define( 'REST_REQUEST', true );
}

class Gutenberg_REST_Block_Editor_Settings_Controller_Test extends WP_Test_REST_Controller_Testcase {
/**
* @var int
Expand Down Expand Up @@ -56,8 +51,7 @@ public function test_register_routes() {
public function test_get_items() {
wp_set_current_user( self::$admin_id );
$request = new WP_REST_Request( 'GET', '/wp-block-editor/v1/settings' );
// Set context for mobile settings.
$_GET['context'] = 'mobile';
$request->set_param( 'context', 'mobile' );
$response = rest_get_server()->dispatch( $request );

Check warning on line 55 in phpunit/experimental/block-editor-settings-mobile-test.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Equals sign not aligned with surrounding assignments; expected 1 space but found 8 spaces
$data = $response->get_data();

Check warning on line 56 in phpunit/experimental/block-editor-settings-mobile-test.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Equals sign not aligned with surrounding assignments; expected 5 spaces but found 12 spaces

Expand Down

0 comments on commit b74ae21

Please sign in to comment.