Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Automattic/remote-data-blocks
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 735af4ecc350804d0a29e27ef1c7c1a62034c22f
Choose a base ref
..
head repository: Automattic/remote-data-blocks
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 320606464ee75516095f35d8624cfbf6fe89825c
Choose a head ref
2 changes: 2 additions & 0 deletions inc/config/airtable-datasource/airtable-datasource.php
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
use RemoteDataBlocks\Config\HttpDatasource;

class AirtableDatasource extends HttpDatasource {
use DynamicDatasource;

private $tables;

public function __construct( private string $access_token, private string $base, mixed $tables ) {
24 changes: 24 additions & 0 deletions inc/config/dynamic-datasource-trait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace RemoteDataBlocks\Config;

trait DynamicDatasource {
private string $slug;
private string $uuid;

public function set_slug( string $slug ): void {
$this->slug = $slug;
}

public function get_slug(): string {
return $this->slug;
}

public function set_uuid( string $uuid ): void {
$this->uuid = $uuid;
}

public function get_uuid(): string {
return $this->uuid;
}
}
2 changes: 2 additions & 0 deletions inc/config/shopify-datasource/class-shopify-datasource.php
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@
use function plugins_url;

class ShopifyDatasource extends HttpDatasource {
use DynamicDatasource;

public function __construct( private string $access_token, private string $store_name ) {}

public function get_store_name(): string {
5 changes: 5 additions & 0 deletions inc/config/shopify-datasource/shopify-datasource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

require_once __DIR__ . '/class-shopify-datasource.php';
require_once __DIR__ . '/class-shopify-get-product-query.php';
require_once __DIR__ . '/class-shopify-search-products-query.php';
10 changes: 6 additions & 4 deletions inc/editor/configuration-loader/configuration-loader.php
Original file line number Diff line number Diff line change
@@ -259,23 +259,25 @@ private static function register_blocks_for_dynamic_data_sources(): void {
switch ( $_source->service ) {
case 'shopify':
$datasource = new ShopifyDatasource( $_source->token, $_source->store );
self::register_blocks_for_shopify_datasource( $datasource );
$datasource->set_uuid( $_source->uuid );
$datasource->set_slug( $_source->slug );
self::register_blocks_for_shopify_data_source( $datasource );
break;
default:
break;
}
}
}

private static function register_blocks_for_shopify_datasource( ShopifyDatasource $datasource ): void {
private static function register_blocks_for_shopify_data_source( ShopifyDatasource $datasource ): void {
$block_name = 'Shopify ' . $datasource->get_store_name();

$shopify_get_product_query = new ShopifyGetProductQuery( $datasource );
self::register_block( $block_name, $shopify_get_product_query );
self::$logger->debug( sprintf( 'Registered "%s" block for dynamic data source', $block_name ) );
self::$logger->debug( sprintf( 'Registered "%s" block for dynamic data source - %s', $block_name, $datasource->get_slug() ) );

$shopify_search_products_query = new ShopifySearchProductsQuery( $datasource );
self::register_search_query( $block_name, $shopify_search_products_query );
self::$logger->debug( sprintf( 'Registered "%s" _search query_ block for dynamic data source', $block_name ) );
self::$logger->debug( sprintf( 'Registered "%s" _search query_ block for dynamic data source - %s', $block_name, $datasource->get_slug() ) );
}
}
3 changes: 3 additions & 0 deletions remote-data-blocks.php
Original file line number Diff line number Diff line change
@@ -26,6 +26,9 @@
require_once __DIR__ . '/inc/autoloader.php';
require_once __DIR__ . '/vendor/autoload.php';

// TODO: Figure out autoloader for this:
require_once __DIR__ . '/inc/config/dynamic-datasource-trait.php';

// Other editor modifications
Editor\AdminNotices::init();
Editor\BlockBindings::init();