If the new settings module is not enabled, return null

This will force the `Settings` old class to always fallback to the old settings value
This commit is contained in:
Narek Zakarian 2025-02-28 19:48:03 +04:00
parent c8d9a142ea
commit 7dc2fef1da
No known key found for this signature in database
GPG key ID: 07AFD7E7A9C164A7

View file

@ -74,6 +74,13 @@ class SettingsMapHelper {
*/
protected GeneralSettingsMapHelper $general_settings_map_helper;
/**
* Whether the new settings module is enabled.
*
* @var bool
*/
protected bool $new_settings_module_enabled;
/**
* Constructor.
*
@ -82,6 +89,7 @@ class SettingsMapHelper {
* @param SettingsTabMapHelper $settings_tab_map_helper A helper for mapping the old/new settings tab settings.
* @param SubscriptionSettingsMapHelper $subscription_map_helper A helper for mapping old and new subscription settings.
* @param GeneralSettingsMapHelper $general_settings_map_helper A helper for mapping old and new general settings.
* @param bool $new_settings_module_enabled Whether the new settings module is enabled.
* @throws RuntimeException When an old key has multiple mappings.
*/
public function __construct(
@ -89,7 +97,8 @@ class SettingsMapHelper {
StylingSettingsMapHelper $styling_settings_map_helper,
SettingsTabMapHelper $settings_tab_map_helper,
SubscriptionSettingsMapHelper $subscription_map_helper,
GeneralSettingsMapHelper $general_settings_map_helper
GeneralSettingsMapHelper $general_settings_map_helper,
bool $new_settings_module_enabled
) {
$this->validate_settings_map( $settings_map );
$this->settings_map = $settings_map;
@ -97,6 +106,7 @@ class SettingsMapHelper {
$this->settings_tab_map_helper = $settings_tab_map_helper;
$this->subscription_map_helper = $subscription_map_helper;
$this->general_settings_map_helper = $general_settings_map_helper;
$this->new_settings_module_enabled = $new_settings_module_enabled;
}
/**
@ -126,6 +136,10 @@ class SettingsMapHelper {
* @return mixed|null The value of the mapped setting, or null if not found.
*/
public function mapped_value( string $old_key ) {
if ( ! $this->new_settings_module_enabled ) {
return null;
}
$this->ensure_map_initialized();
if ( ! isset( $this->key_to_model[ $old_key ] ) ) {
return null;
@ -149,6 +163,10 @@ class SettingsMapHelper {
* @return bool True if the key exists in the new settings, false otherwise.
*/
public function has_mapped_key( string $old_key ) : bool {
if ( ! $this->new_settings_module_enabled ) {
return false;
}
$this->ensure_map_initialized();
return isset( $this->key_to_model[ $old_key ] );