-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto-register blocks for google sheets data sources (#270)
- Loading branch information
1 parent
f601686
commit 1de044c
Showing
5 changed files
with
201 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
inc/Integrations/Google/Sheets/GoogleSheetsIntegration.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace RemoteDataBlocks\Integrations\Google\Sheets; | ||
|
||
use RemoteDataBlocks\WpdbStorage\DataSourceCrud; | ||
|
||
class GoogleSheetsIntegration { | ||
public static function init(): void { | ||
add_action( 'init', [ __CLASS__, 'register_blocks' ], 10, 0 ); | ||
} | ||
|
||
public static function register_blocks(): void { | ||
$data_source_configs = DataSourceCrud::get_configs_by_service( | ||
REMOTE_DATA_BLOCKS_GOOGLE_SHEETS_SERVICE | ||
); | ||
|
||
foreach ( $data_source_configs as $config ) { | ||
$data_source = GoogleSheetsDataSource::from_array( $config ); | ||
self::register_block_for_google_sheets_data_source( $data_source ); | ||
self::register_loop_block_for_google_sheets_data_source( $data_source ); | ||
} | ||
} | ||
|
||
public static function register_block_for_google_sheets_data_source( | ||
GoogleSheetsDataSource $data_source, | ||
array $block_overrides = [] | ||
): void { | ||
register_remote_data_block( | ||
array_merge( | ||
[ | ||
'title' => $data_source->get_display_name(), | ||
'render_query' => [ | ||
'query' => $data_source->___temp_get_query(), | ||
], | ||
'selection_queries' => [ | ||
[ | ||
'query' => $data_source->___temp_get_list_query(), | ||
'type' => 'list', | ||
], | ||
], | ||
], | ||
$block_overrides | ||
) | ||
); | ||
} | ||
|
||
public static function register_loop_block_for_google_sheets_data_source( | ||
GoogleSheetsDataSource $data_source, | ||
array $block_overrides = [] | ||
): void { | ||
register_remote_data_block( | ||
array_merge( | ||
[ | ||
'title' => sprintf( '%s Loop', $data_source->get_display_name() ), | ||
'render_query' => [ | ||
'loop' => true, | ||
'query' => $data_source->___temp_get_list_query(), | ||
], | ||
], | ||
$block_overrides | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters