You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the 'old' approach of setting module config inputfields with getModuleConfigInputfields() it was possible to set the value of an inputfield with $f->attr('value', 'foo') or $f->value = 'foo'. Typically you would set the value to saved field value stored in the $data array, but importantly it still allowed you to set the inputfield value to any other value you want.
But in the newer approach that extends the ModuleConfig class setting the value with $f->attr('value', 'foo') or $f->value = 'foo' only sets the default value of the inputfield and a value set this way is ignored if there is a value stored for the config inputfield in the database.
This makes it difficult to set an inputfield value to something different to the current value stored in the database. You can set the entire module configuration with $modules->saveConfig() but this is a hassle if you only want to set a single value. And this sets the actual database value which is not the same thing as setting an inputfield value (that the user may then adjust).
The text was updated successfully, but these errors were encountered:
This is a difference between the module configuration methods, and one of the benefits to using ModuleConfig or array config methods in my mind. But if you find it's not beneficial for your case, the 'old' approach is not deprecated anything. There are no plans to get rid of it ever, so it might be good to stick with that method if you want to manually set the values. For most cases, manually checking and setting the values (other than default) is just extra effort, which is one of the reasons why we've introduced other configuration options. But for your case where you need to manually populate values, it's not a bad idea to stick with the original way. Note that if using the original way, it's no longer necessary to make the getModuleConfigInputfields() method static (unless you want it to be).
Thanks. Reverting back to getModuleConfigInputfields() is fine. Now that it doesn't need to be static it's quite comfortable setting field values and defaults with: $field->value = $this->my_field_name ?: 'my default value';
In the 'old' approach of setting module config inputfields with getModuleConfigInputfields() it was possible to set the value of an inputfield with
$f->attr('value', 'foo')
or$f->value = 'foo'
. Typically you would set the value to saved field value stored in the $data array, but importantly it still allowed you to set the inputfield value to any other value you want.But in the newer approach that extends the ModuleConfig class setting the value with
$f->attr('value', 'foo')
or$f->value = 'foo'
only sets the default value of the inputfield and a value set this way is ignored if there is a value stored for the config inputfield in the database.This makes it difficult to set an inputfield value to something different to the current value stored in the database. You can set the entire module configuration with $modules->saveConfig() but this is a hassle if you only want to set a single value. And this sets the actual database value which is not the same thing as setting an inputfield value (that the user may then adjust).
The text was updated successfully, but these errors were encountered: