Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] SystemSetting not saving the settings for FieldConfig::TYPE_ARRAY if all options are unselected #22877

Closed
4 tasks done
AltamashShaikh opened this issue Dec 18, 2024 · 0 comments · Fixed by #22885
Closed
4 tasks done
Labels
Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. triaged
Milestone

Comments

@AltamashShaikh
Copy link
Contributor

What happened?

We recently created a new SystemSetting called anonymizeClickIds for AdvertisingConversionExport plugin, below is the code to create the system setting.

$providers = AdvertisingConversionExport::getAvailableClickIdProviders();
        $defaultValues = [];
        $availableValues = [];
        foreach ($providers as $provider) {
            $defaultValues[] = $provider::ID;
            $availableValues[] = ['name' => 'anonymizeClickIds[]', 'value' => $provider->getName(), 'key' => $provider::ID];
        }
$this->makeSetting('anonymizeClickIds', $defaultValues, FieldConfig::TYPE_ARRAY, function (FieldConfig $field) use ($defaultValues, $availableValues) {
            $faqURL = Url::addCampaignParametersToMatomoLink(
                'https://matomo.org/faq/advertising-conversion-export/exported-clickids-have-value-as-anonymized/',
                null,
                null,
                'App.CoreAdminHome.generalSettings'
            );
            $field->introduction = Piwik::translate('AdvertisingConversionExport_AnonymiseClickIDSettingTitle');
            $field->inlineHelp = Piwik::translate(
                'AdvertisingConversionExport_AnonymiseClickIDSettingDescription',
                [
                    '<a target="_blank" rel="noreferrer noopener" href="' . $faqURL . '">',
                    '</a>',
                    '<br><br><strong>',
                    '</strong>',
                ]
            );
            $field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX;
            $field->availableValues = $availableValues;
            $field->validate = function ($values) use ($defaultValues) {
                foreach ($values as $value) {
                    if (!in_array($value, $defaultValues)) {
                        throw new \Exception('Invalid value "' . $value . '"');
                    }
                }
            };
        });

This shows the setting correctly

image

But there is one error, if you unselect all the options and try to save the setting, the setting shows as saved successfully, but it reverts back to the last saved setting.

What should happen?

We should be able to save the setting, with all the options as unselected.

How can this be reproduced?

  1. Activate AdvertisingConversionExport plugin.
  2. Got to system settings, under Admin > System >GeneralSettings
  3. Scroll down to AdvertisingConversionExport section
  4. Unselect all the options for Anonymise Click IDs settings and press save
  5. Refresh the page
  6. Check the setting again.

Matomo version

5.2.0

PHP version

8.3

Server operating system

Linux

What browsers are you seeing the problem on?

No response

Computer operating system

Ubuntu 22.04

Relevant log output

No response

Validations

@AltamashShaikh AltamashShaikh added Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. To Triage An issue awaiting triage by a Matomo core team member labels Dec 18, 2024
@ronak-innocraft ronak-innocraft added triaged and removed To Triage An issue awaiting triage by a Matomo core team member labels Dec 19, 2024
@caddoo caddoo added this to the 5.2.1 milestone Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants