WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.53k stars 4.21k forks source link

The editor settings object doesn't work properly #31701

Closed 5n closed 3 years ago

5n commented 3 years ago

Description

Related #31027 (WordPress/wordpress-develop#1118), #31587, and so on.
Function 'getSettings' doesn't store the settings passed to the block editor.

Step-by-step reproduction instructions

  1. Install and activate Gutenberg plugin.
  2. Install and activate Twenty Twenty-One or TT1 Blocks.
  3. Upload and activate sample-settings plugin.
  4. Go to edit post page ('post', 'page', or custom post like 'wp_template').
  5. Click and add Sample Settings block.
  6. Check the value of custom parameter displayed on sidebar and console log.

Expected behaviour

'sample setting value'

Actual behaviour

undefined

Screenshots or screen recording (optional)

getsettings1 getsettings2

Code snippet (optional)

PHP:

function add_sample_block_editor_settings($settings) {
  $settings['sampleSetting'] = 'sample setting value';
  return $settings;
}
add_filter('block_editor_settings', 'add_sample_block_editor_settings');

'block_editor_settings' -> 'block_editor_settings_all' since 5.8.0.

JSX:

import { store as blockEditorStore } from "@wordpress/block-editor";
import { useSelect, select } from "@wordpress/data";

export default function Edit() {
  const sampleSetting = useSelect((select) => {
    const { getSettings } = select(blockEditorStore);
    return getSettings()?.sampleSetting;
  }, []);
}

WordPress information

Device information

youknowriad commented 3 years ago

Hi, thanks for the issue.

This is not a bug, this is actually the intended behavior. All editor settings don't make sense in the "block-editor" store which is basically something generic enough that can be used in any block editor instance (not WP or post editor specific)

5n commented 3 years ago

I see. Thanks!