Deprecate the $check_key_exists parameter from AssetDataRegistry and disallow duplicate data for all cases (#46139)

* Ensures data is added to the registry just once.

* ditch unnecessary param.

* Deprecate the  param for AssetDataRegistry

* Remove the  param for additional calls to AssetDataRegistry::add()

* Remove the  param for additional call to AssetDataRegistry::add() on WCAdminSharedSettings

* Trigger a PHP warning instead of throwing a fatal whenever the key being registered is not a string and whenever attempting to override existing data.

* Add changefile(s) from automation for the following project(s): woocommerce

* Replace trigger_error with error_log to clear out lint errors.

* Address lint for trigger_error

* Update the test_already_existing_key_on_adding_data test to expect a warning instead of an exception

* Update tests

* Update method from add_data to add.

* Remove the throw InvalidArgumentException for the add and add_data methods.

* Remove the now unnecessary test_already_existing_key_on_adding_data test, considering we now return early whenever the key is duplicated, the code never reaches this stage via AssetDataRegistry:add

* Move the call to the exists method to within the add_data method.

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Patricia Hillebrandt 2024-04-08 18:48:29 -03:00 committed by GitHub
parent b78f1487e5
commit 14c06fff80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 100 additions and 126 deletions

View File

@ -0,0 +1,4 @@
Significance: major
Type: fix
Deprecate the $check_key_exists parameter from AssetDataRegistry and disallow duplicate data for all cases.

View File

@ -297,24 +297,15 @@ class AssetDataRegistry {
* @param string $key The key used to reference the data being registered. This should use camelCase.
* @param mixed $data If not a function, registered to the registry as is. If a function, then the
* callback is invoked right before output to the screen.
* @param boolean $check_key_exists If set to true, duplicate data will be ignored if the key exists.
* @param boolean $check_key_exists Deprecated. If set to true, duplicate data will be ignored if the key exists.
* If false, duplicate data will cause an exception.
*
* @throws InvalidArgumentException Only throws when site is in debug mode. Always logs the error.
*/
public function add( $key, $data, $check_key_exists = false ) {
if ( $check_key_exists && $this->exists( $key ) ) {
return;
if ( $check_key_exists ) {
wc_deprecated_argument( 'Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry::add()', '8.9', 'The $check_key_exists parameter is no longer used: all duplicate data will be ignored if the key exists by default' );
}
try {
$this->add_data( $key, $data );
} catch ( Exception $e ) {
if ( $this->debug() ) {
// bubble up.
throw $e;
}
wc_caught_exception( $e, __METHOD__, [ $key, $data ] );
}
}
/**
@ -414,24 +405,19 @@ class AssetDataRegistry {
*
* @param string $key Key for the data.
* @param mixed $data Value for the data.
*
* @throws InvalidArgumentException If key is not a string or already
* exists in internal data cache.
*/
protected function add_data( $key, $data ) {
if ( ! is_string( $key ) ) {
if ( $this->debug() ) {
throw new InvalidArgumentException(
'Key for the data being registered must be a string'
);
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
trigger_error( esc_html__( 'Key for the data being registered must be a string', 'woocommerce' ), E_USER_WARNING );
return;
}
if ( $this->exists( $key ) ) {
return;
}
if ( isset( $this->data[ $key ] ) ) {
if ( $this->debug() ) {
throw new InvalidArgumentException(
'Overriding existing data with an already registered key is not allowed'
);
}
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
trigger_error( esc_html__( 'Overriding existing data with an already registered key is not allowed', 'woocommerce' ), E_USER_WARNING );
return;
}
if ( \is_callable( $data ) ) {

View File

@ -695,12 +695,12 @@ abstract class AbstractProductGrid extends AbstractDynamicBlock {
*/
protected function enqueue_data( array $attributes = [] ) {
parent::enqueue_data( $attributes );
$this->asset_data_registry->add( 'minColumns', wc_get_theme_support( 'product_blocks::min_columns', 1 ), true );
$this->asset_data_registry->add( 'maxColumns', wc_get_theme_support( 'product_blocks::max_columns', 6 ), true );
$this->asset_data_registry->add( 'defaultColumns', wc_get_theme_support( 'product_blocks::default_columns', 3 ), true );
$this->asset_data_registry->add( 'minRows', wc_get_theme_support( 'product_blocks::min_rows', 1 ), true );
$this->asset_data_registry->add( 'maxRows', wc_get_theme_support( 'product_blocks::max_rows', 6 ), true );
$this->asset_data_registry->add( 'defaultRows', wc_get_theme_support( 'product_blocks::default_rows', 3 ), true );
$this->asset_data_registry->add( 'minColumns', wc_get_theme_support( 'product_blocks::min_columns', 1 ) );
$this->asset_data_registry->add( 'maxColumns', wc_get_theme_support( 'product_blocks::max_columns', 6 ) );
$this->asset_data_registry->add( 'defaultColumns', wc_get_theme_support( 'product_blocks::default_columns', 3 ) );
$this->asset_data_registry->add( 'minRows', wc_get_theme_support( 'product_blocks::min_rows', 1 ) );
$this->asset_data_registry->add( 'maxRows', wc_get_theme_support( 'product_blocks::max_rows', 6 ) );
$this->asset_data_registry->add( 'defaultRows', wc_get_theme_support( 'product_blocks::default_rows', 3 ) );
}
/**

View File

@ -22,13 +22,13 @@ class AllProducts extends AbstractBlock {
protected function enqueue_data( array $attributes = [] ) {
parent::enqueue_data( $attributes );
// Set this so filter blocks being used as widgets know when to render.
$this->asset_data_registry->add( 'hasFilterableProducts', true, true );
$this->asset_data_registry->add( 'minColumns', wc_get_theme_support( 'product_blocks::min_columns', 1 ), true );
$this->asset_data_registry->add( 'maxColumns', wc_get_theme_support( 'product_blocks::max_columns', 6 ), true );
$this->asset_data_registry->add( 'defaultColumns', wc_get_theme_support( 'product_blocks::default_columns', 3 ), true );
$this->asset_data_registry->add( 'minRows', wc_get_theme_support( 'product_blocks::min_rows', 1 ), true );
$this->asset_data_registry->add( 'maxRows', wc_get_theme_support( 'product_blocks::max_rows', 6 ), true );
$this->asset_data_registry->add( 'defaultRows', wc_get_theme_support( 'product_blocks::default_rows', 3 ), true );
$this->asset_data_registry->add( 'hasFilterableProducts', true );
$this->asset_data_registry->add( 'minColumns', wc_get_theme_support( 'product_blocks::min_columns', 1 ) );
$this->asset_data_registry->add( 'maxColumns', wc_get_theme_support( 'product_blocks::max_columns', 6 ) );
$this->asset_data_registry->add( 'defaultColumns', wc_get_theme_support( 'product_blocks::default_columns', 3 ) );
$this->asset_data_registry->add( 'minRows', wc_get_theme_support( 'product_blocks::min_rows', 1 ) );
$this->asset_data_registry->add( 'maxRows', wc_get_theme_support( 'product_blocks::max_rows', 6 ) );
$this->asset_data_registry->add( 'defaultRows', wc_get_theme_support( 'product_blocks::default_rows', 3 ) );
// Hydrate the All Product block with data from the API. This is for the add to cart buttons which show current quantity in cart, and events.
if ( ! is_admin() && ! WC()->is_rest_api_request() ) {

View File

@ -37,7 +37,7 @@ class AllReviews extends AbstractBlock {
*/
protected function enqueue_data( array $attributes = [] ) {
parent::enqueue_data( $attributes );
$this->asset_data_registry->add( 'reviewRatingsEnabled', wc_review_ratings_enabled(), true );
$this->asset_data_registry->add( 'showAvatars', '1' === get_option( 'show_avatars' ), true );
$this->asset_data_registry->add( 'reviewRatingsEnabled', wc_review_ratings_enabled() );
$this->asset_data_registry->add( 'showAvatars', '1' === get_option( 'show_avatars' ) );
}
}

View File

@ -23,7 +23,7 @@ class AttributeFilter extends AbstractBlock {
*/
protected function enqueue_data( array $attributes = [] ) {
parent::enqueue_data( $attributes );
$this->asset_data_registry->add( 'attributes', array_values( wc_get_attribute_taxonomies() ), true );
$this->asset_data_registry->add( 'attributes', array_values( wc_get_attribute_taxonomies() ) );
}
/**

View File

@ -234,21 +234,20 @@ class Cart extends AbstractBlock {
protected function enqueue_data( array $attributes = [] ) {
parent::enqueue_data( $attributes );
$this->asset_data_registry->add( 'countryData', CartCheckoutUtils::get_country_data(), true );
$this->asset_data_registry->add( 'baseLocation', wc_get_base_location(), true );
$this->asset_data_registry->add( 'isShippingCalculatorEnabled', filter_var( get_option( 'woocommerce_enable_shipping_calc' ), FILTER_VALIDATE_BOOLEAN ), true );
$this->asset_data_registry->add( 'displayItemizedTaxes', 'itemized' === get_option( 'woocommerce_tax_total_display' ), true );
$this->asset_data_registry->add( 'displayCartPricesIncludingTax', 'incl' === get_option( 'woocommerce_tax_display_cart' ), true );
$this->asset_data_registry->add( 'taxesEnabled', wc_tax_enabled(), true );
$this->asset_data_registry->add( 'couponsEnabled', wc_coupons_enabled(), true );
$this->asset_data_registry->add( 'shippingEnabled', wc_shipping_enabled(), true );
$this->asset_data_registry->add( 'hasDarkEditorStyleSupport', current_theme_supports( 'dark-editor-style' ), true );
$this->asset_data_registry->add( 'countryData', CartCheckoutUtils::get_country_data() );
$this->asset_data_registry->add( 'baseLocation', wc_get_base_location() );
$this->asset_data_registry->add( 'isShippingCalculatorEnabled', filter_var( get_option( 'woocommerce_enable_shipping_calc' ), FILTER_VALIDATE_BOOLEAN ) );
$this->asset_data_registry->add( 'displayItemizedTaxes', 'itemized' === get_option( 'woocommerce_tax_total_display' ) );
$this->asset_data_registry->add( 'displayCartPricesIncludingTax', 'incl' === get_option( 'woocommerce_tax_display_cart' ) );
$this->asset_data_registry->add( 'taxesEnabled', wc_tax_enabled() );
$this->asset_data_registry->add( 'couponsEnabled', wc_coupons_enabled() );
$this->asset_data_registry->add( 'shippingEnabled', wc_shipping_enabled() );
$this->asset_data_registry->add( 'hasDarkEditorStyleSupport', current_theme_supports( 'dark-editor-style' ) );
$this->asset_data_registry->register_page_id( isset( $attributes['checkoutPageId'] ) ? $attributes['checkoutPageId'] : 0 );
$this->asset_data_registry->add( 'isBlockTheme', wc_current_theme_is_fse_theme(), true );
$this->asset_data_registry->add( 'activeShippingZones', CartCheckoutUtils::get_shipping_zones(), true );
$this->asset_data_registry->add( 'isBlockTheme', wc_current_theme_is_fse_theme() );
$this->asset_data_registry->add( 'activeShippingZones', CartCheckoutUtils::get_shipping_zones() );
$pickup_location_settings = LocalPickupUtils::get_local_pickup_settings();
$this->asset_data_registry->add( 'localPickupEnabled', $pickup_location_settings['enabled'], true );
$this->asset_data_registry->add( 'localPickupEnabled', $pickup_location_settings['enabled'] );
// Hydrate the following data depending on admin or frontend context.
if ( ! is_admin() && ! WC()->is_rest_api_request() ) {

View File

@ -333,39 +333,37 @@ class Checkout extends AbstractBlock {
$country_data[ $country_code ]['format'] = $format;
}
$this->asset_data_registry->add( 'countryData', $country_data, true );
$this->asset_data_registry->add( 'defaultAddressFormat', $address_formats['default'], true );
$this->asset_data_registry->add( 'baseLocation', wc_get_base_location(), true );
$this->asset_data_registry->add( 'countryData', $country_data );
$this->asset_data_registry->add( 'defaultAddressFormat', $address_formats['default'] );
$this->asset_data_registry->add( 'baseLocation', wc_get_base_location() );
$this->asset_data_registry->add(
'checkoutAllowsGuest',
false === filter_var(
wc()->checkout()->is_registration_required(),
FILTER_VALIDATE_BOOLEAN
),
true
)
);
$this->asset_data_registry->add(
'checkoutAllowsSignup',
filter_var(
wc()->checkout()->is_registration_enabled(),
FILTER_VALIDATE_BOOLEAN
),
true
)
);
$this->asset_data_registry->add( 'checkoutShowLoginReminder', filter_var( get_option( 'woocommerce_enable_checkout_login_reminder' ), FILTER_VALIDATE_BOOLEAN ), true );
$this->asset_data_registry->add( 'displayCartPricesIncludingTax', 'incl' === get_option( 'woocommerce_tax_display_cart' ), true );
$this->asset_data_registry->add( 'displayItemizedTaxes', 'itemized' === get_option( 'woocommerce_tax_total_display' ), true );
$this->asset_data_registry->add( 'forcedBillingAddress', 'billing_only' === get_option( 'woocommerce_ship_to_destination' ), true );
$this->asset_data_registry->add( 'taxesEnabled', wc_tax_enabled(), true );
$this->asset_data_registry->add( 'couponsEnabled', wc_coupons_enabled(), true );
$this->asset_data_registry->add( 'shippingEnabled', wc_shipping_enabled(), true );
$this->asset_data_registry->add( 'hasDarkEditorStyleSupport', current_theme_supports( 'dark-editor-style' ), true );
$this->asset_data_registry->add( 'checkoutShowLoginReminder', filter_var( get_option( 'woocommerce_enable_checkout_login_reminder' ), FILTER_VALIDATE_BOOLEAN ) );
$this->asset_data_registry->add( 'displayCartPricesIncludingTax', 'incl' === get_option( 'woocommerce_tax_display_cart' ) );
$this->asset_data_registry->add( 'displayItemizedTaxes', 'itemized' === get_option( 'woocommerce_tax_total_display' ) );
$this->asset_data_registry->add( 'forcedBillingAddress', 'billing_only' === get_option( 'woocommerce_ship_to_destination' ) );
$this->asset_data_registry->add( 'taxesEnabled', wc_tax_enabled() );
$this->asset_data_registry->add( 'couponsEnabled', wc_coupons_enabled() );
$this->asset_data_registry->add( 'shippingEnabled', wc_shipping_enabled() );
$this->asset_data_registry->add( 'hasDarkEditorStyleSupport', current_theme_supports( 'dark-editor-style' ) );
$this->asset_data_registry->register_page_id( isset( $attributes['cartPageId'] ) ? $attributes['cartPageId'] : 0 );
$this->asset_data_registry->add( 'isBlockTheme', wc_current_theme_is_fse_theme(), true );
$this->asset_data_registry->add( 'isBlockTheme', wc_current_theme_is_fse_theme() );
$pickup_location_settings = LocalPickupUtils::get_local_pickup_settings();
$this->asset_data_registry->add( 'localPickupEnabled', $pickup_location_settings['enabled'], true );
$this->asset_data_registry->add( 'localPickupText', $pickup_location_settings['title'], true );
$this->asset_data_registry->add( 'localPickupEnabled', $pickup_location_settings['enabled'] );
$this->asset_data_registry->add( 'localPickupText', $pickup_location_settings['title'] );
$is_block_editor = $this->is_block_editor();

View File

@ -52,7 +52,7 @@ class ClassicTemplate extends AbstractDynamicBlock {
// Indicate to interactivity powered components that this block is on the page,
// and needs refresh to update data.
$this->asset_data_registry->add( 'needsRefreshForInteractivityAPI', true, true );
$this->asset_data_registry->add( 'needsRefreshForInteractivityAPI', true );
}
/**
@ -133,15 +133,14 @@ class ClassicTemplate extends AbstractDynamicBlock {
if ( $valid ) {
// Set this so that our product filters can detect if it's a PHP template.
$this->asset_data_registry->add( 'isRenderingPhpTemplate', true, true );
$this->asset_data_registry->add( 'isRenderingPhpTemplate', true );
// Set this so filter blocks being used as widgets know when to render.
$this->asset_data_registry->add( 'hasFilterableProducts', true, true );
$this->asset_data_registry->add( 'hasFilterableProducts', true );
$this->asset_data_registry->add(
'pageUrl',
html_entity_decode( get_pagenum_link() ),
''
html_entity_decode( get_pagenum_link() )
);
return $this->render_archive_product();

View File

@ -322,6 +322,6 @@ abstract class FeaturedItem extends AbstractDynamicBlock {
*/
protected function enqueue_data( array $attributes = [] ) {
parent::enqueue_data( $attributes );
$this->asset_data_registry->add( 'defaultHeight', wc_get_theme_support( 'featured_block::default_height', 500 ), true );
$this->asset_data_registry->add( 'defaultHeight', wc_get_theme_support( 'featured_block::default_height', 500 ) );
}
}

View File

@ -159,15 +159,13 @@ class MiniCart extends AbstractBlock {
$this->asset_data_registry->add(
'taxLabel',
$this->tax_label,
''
$this->tax_label
);
}
$this->asset_data_registry->add(
'displayCartPricesIncludingTax',
$this->display_cart_prices_including_tax,
true
$this->display_cart_prices_including_tax
);
$template_part_edit_uri = '';
@ -206,8 +204,7 @@ class MiniCart extends AbstractBlock {
$this->asset_data_registry->add(
'templatePartEditUri',
$template_part_edit_uri,
''
$template_part_edit_uri
);
/**

View File

@ -51,6 +51,6 @@ class BillingAddress extends AbstractOrderConfirmationBlock {
*/
protected function enqueue_data( array $attributes = [] ) {
parent::enqueue_data( $attributes );
$this->asset_data_registry->add( 'additionalAddressFields', Package::container()->get( CheckoutFields::class )->get_fields_for_location( 'address' ), true );
$this->asset_data_registry->add( 'additionalAddressFields', Package::container()->get( CheckoutFields::class )->get_fields_for_location( 'address' ) );
}
}

View File

@ -51,6 +51,6 @@ class ShippingAddress extends AbstractOrderConfirmationBlock {
*/
protected function enqueue_data( array $attributes = [] ) {
parent::enqueue_data( $attributes );
$this->asset_data_registry->add( 'additionalAddressFields', Package::container()->get( CheckoutFields::class )->get_fields_for_location( 'address' ), true );
$this->asset_data_registry->add( 'additionalAddressFields', Package::container()->get( CheckoutFields::class )->get_fields_for_location( 'address' ) );
}
}

View File

@ -354,7 +354,7 @@ class ProductCollection extends AbstractBlock {
// The `loop_shop_per_page` filter can be found in WC_Query::product_query().
// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
$this->asset_data_registry->add( 'loopShopPerPage', apply_filters( 'loop_shop_per_page', wc_get_default_products_per_row() * wc_get_default_product_rows_per_page() ), true );
$this->asset_data_registry->add( 'loopShopPerPage', apply_filters( 'loop_shop_per_page', wc_get_default_products_per_row() * wc_get_default_product_rows_per_page() ) );
}
/**
@ -415,12 +415,12 @@ class ProductCollection extends AbstractBlock {
}
$this->parsed_block = $parsed_block;
$this->asset_data_registry->add( 'hasFilterableProducts', true, true );
$this->asset_data_registry->add( 'hasFilterableProducts', true );
/**
* It enables the page to refresh when a filter is applied, ensuring that the product collection block,
* which is a server-side rendered (SSR) block, retrieves the products that match the filters.
*/
$this->asset_data_registry->add( 'isRenderingPhpTemplate', true, true );
$this->asset_data_registry->add( 'isRenderingPhpTemplate', true );
return $pre_render;
}

View File

@ -47,10 +47,10 @@ final class ProductFilter extends AbstractBlock {
global $pagenow;
parent::enqueue_data( $attributes );
$this->asset_data_registry->add( 'isBlockTheme', wc_current_theme_is_fse_theme(), true );
$this->asset_data_registry->add( 'isProductArchive', is_shop() || is_product_taxonomy(), true );
$this->asset_data_registry->add( 'isSiteEditor', 'site-editor.php' === $pagenow, true );
$this->asset_data_registry->add( 'isWidgetEditor', 'widgets.php' === $pagenow || 'customize.php' === $pagenow, true );
$this->asset_data_registry->add( 'isBlockTheme', wc_current_theme_is_fse_theme() );
$this->asset_data_registry->add( 'isProductArchive', is_shop() || is_product_taxonomy() );
$this->asset_data_registry->add( 'isSiteEditor', 'site-editor.php' === $pagenow );
$this->asset_data_registry->add( 'isWidgetEditor', 'widgets.php' === $pagenow || 'customize.php' === $pagenow );
}
/**

View File

@ -110,8 +110,8 @@ final class ProductFilterStockStatus extends AbstractBlock {
*/
protected function enqueue_data( array $stock_statuses = [] ) {
parent::enqueue_data( $stock_statuses );
$this->asset_data_registry->add( 'stockStatusOptions', wc_get_product_stock_status_options(), true );
$this->asset_data_registry->add( 'hideOutOfStockItems', 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ), true );
$this->asset_data_registry->add( 'stockStatusOptions', wc_get_product_stock_status_options() );
$this->asset_data_registry->add( 'hideOutOfStockItems', 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) );
}
/**

View File

@ -180,7 +180,7 @@ class ProductImage extends AbstractBlock {
* not in the post content on editor load.
*/
protected function enqueue_data( array $attributes = [] ) {
$this->asset_data_registry->add( 'isBlockThemeEnabled', wc_current_theme_is_fse_theme(), false );
$this->asset_data_registry->add( 'isBlockThemeEnabled', wc_current_theme_is_fse_theme() );
}

View File

@ -132,7 +132,7 @@ class ProductQuery extends AbstractBlock {
// The `loop_shop_per_page` filter can be found in WC_Query::product_query().
// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
$this->asset_data_registry->add( 'loopShopPerPage', apply_filters( 'loop_shop_per_page', wc_get_default_products_per_row() * wc_get_default_product_rows_per_page() ), true );
$this->asset_data_registry->add( 'loopShopPerPage', apply_filters( 'loop_shop_per_page', wc_get_default_products_per_row() * wc_get_default_product_rows_per_page() ) );
}
/**
@ -180,12 +180,11 @@ class ProductQuery extends AbstractBlock {
// and needs refresh to update data.
$this->asset_data_registry->add(
'needsRefreshForInteractivityAPI',
true,
true
);
// Set this so that our product filters can detect if it's a PHP template.
$this->asset_data_registry->add( 'hasFilterableProducts', true, true );
$this->asset_data_registry->add( 'isRenderingPhpTemplate', true, true );
$this->asset_data_registry->add( 'hasFilterableProducts', true );
$this->asset_data_registry->add( 'isRenderingPhpTemplate', true );
add_filter(
'query_loop_block_query_vars',
array( $this, 'build_query' ),

View File

@ -64,7 +64,7 @@ class ProductTag extends AbstractProductGrid {
$tag_count = wp_count_terms( 'product_tag' );
$this->asset_data_registry->add( 'hasTags', $tag_count > 0, true );
$this->asset_data_registry->add( 'limitTags', $tag_count > 100, true );
$this->asset_data_registry->add( 'hasTags', $tag_count > 0 );
$this->asset_data_registry->add( 'limitTags', $tag_count > 100 );
}
}

View File

@ -37,7 +37,7 @@ class ReviewsByCategory extends AbstractBlock {
*/
protected function enqueue_data( array $attributes = [] ) {
parent::enqueue_data( $attributes );
$this->asset_data_registry->add( 'reviewRatingsEnabled', wc_review_ratings_enabled(), true );
$this->asset_data_registry->add( 'showAvatars', '1' === get_option( 'show_avatars' ), true );
$this->asset_data_registry->add( 'reviewRatingsEnabled', wc_review_ratings_enabled() );
$this->asset_data_registry->add( 'showAvatars', '1' === get_option( 'show_avatars' ) );
}
}

View File

@ -37,7 +37,7 @@ class ReviewsByProduct extends AbstractBlock {
*/
protected function enqueue_data( array $attributes = [] ) {
parent::enqueue_data( $attributes );
$this->asset_data_registry->add( 'reviewRatingsEnabled', wc_review_ratings_enabled(), true );
$this->asset_data_registry->add( 'showAvatars', '1' === get_option( 'show_avatars' ), true );
$this->asset_data_registry->add( 'reviewRatingsEnabled', wc_review_ratings_enabled() );
$this->asset_data_registry->add( 'showAvatars', '1' === get_option( 'show_avatars' ) );
}
}

View File

@ -22,8 +22,8 @@ class StockFilter extends AbstractBlock {
*/
protected function enqueue_data( array $stock_statuses = [] ) {
parent::enqueue_data( $stock_statuses );
$this->asset_data_registry->add( 'stockStatusOptions', wc_get_product_stock_status_options(), true );
$this->asset_data_registry->add( 'hideOutOfStockItems', 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ), true );
$this->asset_data_registry->add( 'stockStatusOptions', wc_get_product_stock_status_options() );
$this->asset_data_registry->add( 'hideOutOfStockItems', 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) );
}

View File

@ -233,8 +233,8 @@ class CheckoutFields {
* Add fields data to the asset data registry.
*/
public function add_fields_data() {
$this->asset_data_registry->add( 'defaultFields', array_merge( $this->get_core_fields(), $this->get_additional_fields() ), true );
$this->asset_data_registry->add( 'addressFieldsLocations', $this->fields_locations, true );
$this->asset_data_registry->add( 'defaultFields', array_merge( $this->get_core_fields(), $this->get_additional_fields() ) );
$this->asset_data_registry->add( 'addressFieldsLocations', $this->fields_locations );
}
/**

View File

@ -57,12 +57,11 @@ class ShippingController {
'countryStates',
function () {
return WC()->countries->get_states();
},
true
}
);
}
$this->asset_data_registry->add( 'collectableMethodIds', array( 'Automattic\WooCommerce\StoreApi\Utilities\LocalPickupUtils', 'get_local_pickup_method_ids' ), true );
$this->asset_data_registry->add( 'collectableMethodIds', array( 'Automattic\WooCommerce\StoreApi\Utilities\LocalPickupUtils', 'get_local_pickup_method_ids' ) );
$this->asset_data_registry->add( 'shippingCostRequiresAddress', get_option( 'woocommerce_shipping_cost_requires_address', false ) === 'yes' );
add_action( 'rest_api_init', array( $this, 'register_settings' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );

View File

@ -60,7 +60,7 @@ class ClassicTemplatesCompatibility {
global $pagenow;
if ( is_shop() || is_product_taxonomy() || 'widgets.php' === $pagenow ) {
$this->asset_data_registry->add( 'hasFilterableProducts', true, true );
$this->asset_data_registry->add( 'hasFilterableProducts', true );
}
}
@ -75,7 +75,7 @@ class ClassicTemplatesCompatibility {
*/
public function set_php_template_data() {
if ( is_shop() || is_product_taxonomy() ) {
$this->asset_data_registry->add( 'isRenderingPhpTemplate', true, true );
$this->asset_data_registry->add( 'isRenderingPhpTemplate', true );
}
}
}

View File

@ -59,8 +59,7 @@ class WCAdminSharedSettings {
$this->settings_prefix,
function() {
return apply_filters( 'woocommerce_admin_shared_settings', array() );
},
true
}
);
}
}

View File

@ -49,16 +49,10 @@ class AssetDataRegistry extends \WP_UnitTestCase {
}
public function test_invalid_key_on_adding_data() {
$this->expectException( InvalidArgumentException::class );
$this->setExpectedException( 'PHPUnit_Framework_Error_Warning' );
$this->registry->add( [ 'some_value' ], 'foo' );
}
public function test_already_existing_key_on_adding_data() {
$this->registry->add( 'foo', 'bar' );
$this->expectException( InvalidArgumentException::class );
$this->registry->add( 'foo', 'yar' );
}
/**
* This tests the 'woocommerce_shared_settings' filter.
*/