diff --git a/inc/Editor/BlockManagement/ConfigRegistry.php b/inc/Editor/BlockManagement/ConfigRegistry.php index c8141f737..ca719b324 100644 --- a/inc/Editor/BlockManagement/ConfigRegistry.php +++ b/inc/Editor/BlockManagement/ConfigRegistry.php @@ -51,7 +51,12 @@ public static function register_block( array $user_config = [] ): bool|WP_Error $display_query = self::inflate_query( $user_config[ self::RENDER_QUERY_KEY ]['query'] ); $input_schema = $display_query->get_input_schema(); - $is_loop = $user_config[ self::RENDER_QUERY_KEY ]['loop'] ?? false; + // Check if any variables are required + $has_required_variables = array_reduce( + array_column( $input_schema, 'required' ), + fn( $carry, $required ) => $carry || ( $required ?? true ), + false + ); // Build the base configuration for the block. This is our own internal // configuration, not what will be passed to WordPress's register_block_type. @@ -61,7 +66,7 @@ public static function register_block( array $user_config = [] ): bool|WP_Error 'icon' => $user_config['icon'] ?? 'cloud', 'instructions' => $user_config['instructions'] ?? null, 'name' => $block_name, - 'loop' => $is_loop, + 'loop' => $user_config[ self::RENDER_QUERY_KEY ]['loop'] ?? false, 'overrides' => $user_config['overrides'] ?? [], 'patterns' => [], 'queries' => [ @@ -78,9 +83,9 @@ public static function register_block( array $user_config = [] ): bool|WP_Error 'type' => $input_var['type'] ?? 'string', ]; }, array_keys( $input_schema ), array_values( $input_schema ) ), - 'name' => $is_loop ? 'Collection' : 'Manual input', + 'name' => $has_required_variables ? 'Manual input' : 'Load collection', 'query_key' => self::DISPLAY_QUERY_KEY, - 'type' => $is_loop ? 'loop' : 'input', + 'type' => $has_required_variables ? 'input' : 'collection', ], ], 'title' => $block_title, diff --git a/src/blocks/remote-data-container/components/placeholders/ItemSelectQueryType.tsx b/src/blocks/remote-data-container/components/placeholders/ItemSelectQueryType.tsx index a57fdb0c5..05d41377b 100644 --- a/src/blocks/remote-data-container/components/placeholders/ItemSelectQueryType.tsx +++ b/src/blocks/remote-data-container/components/placeholders/ItemSelectQueryType.tsx @@ -38,8 +38,13 @@ export function ItemSelectQueryType( props: ItemSelectQueryTypeProps ) { { ...selectorProps } /> ); + case 'collection': + return ( + + ); case 'input': - case 'loop': if ( selector.inputs.length === 1 && selector.inputs[ 0 ] ) { return ( ; } - return ( - - ); - return null; } ) }