Error configuring SystemSetting feature in a Plugin


(Tassoman) #1

While I’m adding Settings feature to my plugin because I want let superadmins decide their users experience.

To do so I’ve extended \Piwik\Plugin\Settings class in my plugin, defining my two SystemSettings checkboxes, providing a default value, making them readable by standard users.

I’ve followed ExampleSettings Plugin, but I feel there’s something wrong because when I try to login Piwik 2.3.0 using a standard user I get an error notification each page: Non sei abilitato a cambiare il valore dell’impostazione “profiles” nel plugin "RerUserDates’’

In english sounds like. "Your’re not allowed modifying settings value “profiles” in plugin “RerUserDates”. This sad message is looking as an error notice while login form. Then become an Exception when standard user logs in, stopping Piwik entirely.

Diving in the code I’ve discovered removeAllPluginSettings() method. So I’ve implemented it on plugin’s deactivation() method call. (that’s not described into ExampleSettings plugin shipped with core)

So what’s wrong with data SystemSetting? I’m expecting this value called “profiles” was already set on plugin activation (because of default value).


    /**
     * Delete settings on deactivation
     */
    public  function deactivate()
    {
        $settings = new Settings('RerUserDates');
        $settings->removeAllPluginSettings();
    }


    /**
     * Definition of Profiles SystemSetting
     */
    private function createProfileSettings()
    {
        $this->profiles = new SystemSetting('profiles', Piwik::translate('RerUserDates_SettingsProfiles'));
        $this->profiles->readableByCurrentUser = true;
        $this->profiles->type = static::TYPE_BOOL;
        $this->profiles->uiControlType = static::CONTROL_CHECKBOX;
        $this->profiles->description = Piwik::translate('RerUserDates_SettingsProfilesDescription');
        $this->profiles->defaultValue = true;

        $this->addSetting($this->profiles);
    }


#2

Hi Tassoman,

Setting the “readableByCurrentUser” property is exactly what you need to do. Unfortunately, this feature was added in Piwik 2.4.0 which will be released in about 1-2 weeks. That’s why it doesn’t work for you right now.

Regarding “deactivate” and “removeAllPluginSettings”: You do not really have to do this. The Piwik framework is doing this automatically for you if the plugin gets uninstalled. If you want to have this feature on deactivate then you can leave the code there.

Let me know in case you have any question.


(Tassoman) #3

Would be useful having @since annotation for each class and method inside the source code, just to avoid this mess.
It happened twice I’ve coded relying on beta features for a stable plugin release ::o


#4

Absolutely! We will do better in the future.

Thanks for letting us know