Skip to content

Commit 6d19460

Browse files
committed
Fix register_block_configuration() to persist block configurations
1 parent b078b92 commit 6d19460

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

inc/Editor/BlockManagement/BlockRegistration.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,27 @@ public static function add_block_category( array $block_categories ): array {
3232
}
3333

3434
public static function register_blocks(): void {
35-
$remote_data_blocks_config = [];
35+
$all_remote_data_config = [];
3636
$scripts_to_localize = [];
3737

38-
foreach ( ConfigStore::get_block_configurations() as $config ) {
39-
self::register_block_config( $config );
38+
foreach ( ConfigStore::get_block_configurations() as $block_configuration ) {
39+
$block_name = $block_configuration['name'];
40+
41+
[ $config, $script_handle ] = self::register_block_configuration( $block_configuration );
42+
$all_remote_data_config[ $block_name ] = $config;
43+
$scripts_to_localize[] = $script_handle;
4044
}
4145

4246
foreach ( array_unique( $scripts_to_localize ) as $script_handle ) {
4347
wp_localize_script( $script_handle, 'REMOTE_DATA_BLOCKS', [
44-
'config' => $remote_data_blocks_config,
48+
'config' => $all_remote_data_config,
4549
'rest_url' => RemoteDataController::get_url(),
4650
'tracks_global_properties' => TracksAnalytics::get_global_properties(),
4751
] );
4852
}
4953
}
5054

51-
public static function register_block_config( array $config ): void {
55+
public static function register_block_configuration( array $config ): array {
5256
$block_name = $config['name'];
5357
$block_path = REMOTE_DATA_BLOCKS__PLUGIN_DIRECTORY . '/build/blocks/remote-data-container';
5458

@@ -74,7 +78,7 @@ public static function register_block_config( array $config ): void {
7478
}
7579

7680
// Create the localized data that will be used by our block editor script.
77-
$remote_data_blocks_config[ $block_name ] = [
81+
$block_config = [
7882
'availableBindings' => $available_bindings,
7983
'loop' => $config['loop'],
8084
'name' => $block_name,
@@ -101,10 +105,12 @@ public static function register_block_config( array $config ): void {
101105

102106
$block_type = register_block_type( $block_path, $block_options );
103107

104-
$scripts_to_localize[] = $block_type->editor_script_handles[0];
108+
$script_handle = $block_type->editor_script_handles[0];
105109

106110
// Register a default pattern that simply displays the available data.
107111
$default_pattern_name = BlockPatterns::register_default_block_pattern( $block_name, $config['title'], $config['queries'][ ConfigRegistry::DISPLAY_QUERY_KEY ] );
108-
$remote_data_blocks_config[ $block_name ]['patterns']['default'] = $default_pattern_name;
112+
$block_config['patterns']['default'] = $default_pattern_name;
113+
114+
return [ $block_config, $script_handle ];
109115
}
110116
}

0 commit comments

Comments
 (0)