do only overwrite settings, which can be altered in current screen

This commit is contained in:
David Remer 2020-07-10 08:41:23 +03:00
parent bf1737a22e
commit 8fef1ec612
2 changed files with 9 additions and 2 deletions

View file

@ -62,11 +62,12 @@ return [
$settings = $container->get('wcgateway.settings'); $settings = $container->get('wcgateway.settings');
$fields = $container->get('wcgateway.settings.fields'); $fields = $container->get('wcgateway.settings.fields');
$webhookRegistrar = $container->get('webhook.registrar'); $webhookRegistrar = $container->get('webhook.registrar');
$state = $container->get('onboarding.state');
global $wpdb; global $wpdb;
$cacheFactory = new CachePoolFactory($wpdb); $cacheFactory = new CachePoolFactory($wpdb);
$pool = $cacheFactory->createCachePool('ppcp-token'); $pool = $cacheFactory->createCachePool('ppcp-token');
return new SettingsListener($settings, $fields, $webhookRegistrar, $pool); return new SettingsListener($settings, $fields, $webhookRegistrar, $pool, $state);
}, },
'wcgateway.order-processor' => static function (ContainerInterface $container): OrderProcessor { 'wcgateway.order-processor' => static function (ContainerInterface $container): OrderProcessor {

View file

@ -17,17 +17,20 @@ class SettingsListener
private $settingFields; private $settingFields;
private $webhookRegistrar; private $webhookRegistrar;
private $cache; private $cache;
private $state;
public function __construct( public function __construct(
Settings $settings, Settings $settings,
array $settingFields, array $settingFields,
WebhookRegistrar $webhookRegistrar, WebhookRegistrar $webhookRegistrar,
CacheInterface $cache CacheInterface $cache,
State $state
) { ) {
$this->settings = $settings; $this->settings = $settings;
$this->settingFields = $settingFields; $this->settingFields = $settingFields;
$this->webhookRegistrar = $webhookRegistrar; $this->webhookRegistrar = $webhookRegistrar;
$this->cache = $cache; $this->cache = $cache;
$this->state = $state;
} }
public function listen() public function listen()
@ -73,6 +76,9 @@ class SettingsListener
{ {
$settings = []; $settings = [];
foreach ($this->settingFields as $key => $config) { foreach ($this->settingFields as $key => $config) {
if (! in_array($this->state->currentState(), $config['screens'], true)) {
continue;
}
switch ($config['type']) { switch ($config['type']) {
case 'checkbox': case 'checkbox':
$settings[$key] = isset($rawData[$key]); $settings[$key] = isset($rawData[$key]);