@@ -32,23 +32,27 @@ public static function add_block_category( array $block_categories ): array {
32
32
}
33
33
34
34
public static function register_blocks (): void {
35
- $ remote_data_blocks_config = [];
35
+ $ all_remote_data_config = [];
36
36
$ scripts_to_localize = [];
37
37
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 ;
40
44
}
41
45
42
46
foreach ( array_unique ( $ scripts_to_localize ) as $ script_handle ) {
43
47
wp_localize_script ( $ script_handle , 'REMOTE_DATA_BLOCKS ' , [
44
- 'config ' => $ remote_data_blocks_config ,
48
+ 'config ' => $ all_remote_data_config ,
45
49
'rest_url ' => RemoteDataController::get_url (),
46
50
'tracks_global_properties ' => TracksAnalytics::get_global_properties (),
47
51
] );
48
52
}
49
53
}
50
54
51
- public static function register_block_config ( array $ config ): void {
55
+ public static function register_block_configuration ( array $ config ): array {
52
56
$ block_name = $ config ['name ' ];
53
57
$ block_path = REMOTE_DATA_BLOCKS__PLUGIN_DIRECTORY . '/build/blocks/remote-data-container ' ;
54
58
@@ -74,7 +78,7 @@ public static function register_block_config( array $config ): void {
74
78
}
75
79
76
80
// Create the localized data that will be used by our block editor script.
77
- $ remote_data_blocks_config [ $ block_name ] = [
81
+ $ block_config = [
78
82
'availableBindings ' => $ available_bindings ,
79
83
'loop ' => $ config ['loop ' ],
80
84
'name ' => $ block_name ,
@@ -101,10 +105,12 @@ public static function register_block_config( array $config ): void {
101
105
102
106
$ block_type = register_block_type ( $ block_path , $ block_options );
103
107
104
- $ scripts_to_localize [] = $ block_type ->editor_script_handles [0 ];
108
+ $ script_handle = $ block_type ->editor_script_handles [0 ];
105
109
106
110
// Register a default pattern that simply displays the available data.
107
111
$ 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 ];
109
115
}
110
116
}
0 commit comments