mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Pass the PaymentSettings model instance to styling helper.
Once the new settings module is permanently enabled, this model can be passed as a dependency to the styling helper class. For now, we must pass it this way to avoid errors when the new settings module is disabled.
This commit is contained in:
parent
e83dba1506
commit
b74cfba72b
1 changed files with 26 additions and 1 deletions
|
@ -10,7 +10,9 @@ declare( strict_types = 1 );
|
|||
namespace WooCommerce\PayPalCommerce\Compat\Settings;
|
||||
|
||||
use RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\Settings\Data\AbstractDataModel;
|
||||
use WooCommerce\PayPalCommerce\Settings\Data\GeneralSettings;
|
||||
use WooCommerce\PayPalCommerce\Settings\Data\PaymentSettings;
|
||||
use WooCommerce\PayPalCommerce\Settings\Data\SettingsModel;
|
||||
use WooCommerce\PayPalCommerce\Settings\Data\StylingSettings;
|
||||
|
||||
|
@ -169,7 +171,11 @@ class SettingsMapHelper {
|
|||
|
||||
switch ( true ) {
|
||||
case $model instanceof StylingSettings:
|
||||
return $this->styling_settings_map_helper->mapped_value( $old_key, $this->model_cache[ $model_id ] );
|
||||
return $this->styling_settings_map_helper->mapped_value(
|
||||
$old_key,
|
||||
$this->model_cache[ $model_id ],
|
||||
$this->get_payment_settings_model()
|
||||
);
|
||||
|
||||
case $model instanceof GeneralSettings:
|
||||
return $this->general_settings_map_helper->mapped_value( $old_key, $this->model_cache[ $model_id ] );
|
||||
|
@ -217,4 +223,23 @@ class SettingsMapHelper {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the PaymentSettings model instance.
|
||||
*
|
||||
* Once the new settings module is permanently enabled,
|
||||
* this model can be passed as a dependency to the appropriate helper classes.
|
||||
* For now, we must pass it this way to avoid errors when the new settings module is disabled.
|
||||
*
|
||||
* @return PaymentSettings|null
|
||||
*/
|
||||
protected function get_payment_settings_model() : ?AbstractDataModel {
|
||||
foreach ( $this->settings_map as $settings_map_instance ) {
|
||||
if ( $settings_map_instance->get_model() instanceof PaymentSettings ) {
|
||||
return $settings_map_instance->get_model();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue