How to manipulate plugin configuration variables ($plugin_cf)

A place to report and discuss bugs - please mention CMSimple-version, server, platform and browser version
simpleSolutions.dk
Posts: 132
Joined: Thu Oct 06, 2011 7:00 am

How to manipulate plugin configuration variables ($plugin_cf)

Postby simpleSolutions.dk » Wed Sep 27, 2017 10:38 pm

It is not a bug, but a serious issue.
In version previous to 1.7 it was possible to overwrite values of configuration values in plugins on the fly, i.e.
$plugin_cf['plugin_name'].['value']=$new_value
was executed and the plugin configuration changed to a new value. This functionality could be used to change plugins default configuration to alternate behaviour. I used this possibility in many of mine plugins, among other in PHP Viewer where some documents needs to be refreshed frequently (eg sports results) and other never change. in order to satisfy both needs it's necessary to change plugins configuration on some pages, or even the same page displaying to different pdf documents.

The possibility to manipulate configuration variables seems to be gone in CMSimple_XH version 1.7. and I get the warning: "Indirect modification of overloaded element of XH\PluginConfig has no effect", and it really has no effect. Of course it can be solved by passing all configurations values to plugin function but it's against the idea of having configurations variables. Any suggestion how to manipulate plugins configuration variables in version 1.7?

manu
Posts: 615
Joined: Wed Jun 04, 2008 12:05 pm
Location: St. Gallen - Schweiz
Contact:

Re: How to manipulate plugin configuration variables ($plugin_cf)

Postby manu » Thu Sep 28, 2017 7:28 am

IMO it is correct to generally protect the plugin configuration. Otherwise you could overwrite config values of plugins other than yours.
If you want to modify configuration values you better copy them to your own local configuration set in your environment. and use it from there.

cmb
Posts: 11717
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: How to manipulate plugin configuration variables ($plugin_cf)

Postby cmb » Thu Sep 28, 2017 9:56 am

simpleSolutions.dk wrote:The possibility to manipulate configuration variables seems to be gone in CMSimple_XH version 1.7. and I get the warning: "Indirect modification of overloaded element of XH\PluginConfig has no effect", and it really has no effect.

This change has been introduced by implementing Lazy loading of plugin config and language files. Preventing write access to $plugin_cf|tx was not the reason for the implementation, but rather a side-effect. I guess even that could be fixed (would probably require references), but I agree with manu that it's better not to change any configuration or language settings from a plugin, but to leave all manipulation to the core.

simpleSolutions.dk wrote:Of course it can be solved by passing all configurations values to plugin function but it's against the idea of having configurations variables. Any suggestion how to manipulate plugins configuration variables in version 1.7?

Instead of manipulation configuration variables, what about using an own global variable, if necessary? For instance:

Code: Select all

function my_plugin($a_setting = null)
{
    global $my_plugin_setting, $plugin_cf;

    $my_plugin_setting = isset($a_setting) ? $a_setting : $plugin_cf['my_plugin']['a_setting'];
    // actual code using $my_plugin_setting  instead of $plugin_cf['my_plugin']['a_setting']
Christoph M. Becker –Plugins for CMSimple_XH, but not for CMSimple 4+


Return to “Bugs”

Who is online

Users browsing this forum: No registered users and 1 guest