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

Cannot set inputfield value in module config #2010

Closed
Toutouwai opened this issue Aug 31, 2016 · 2 comments
Closed

Cannot set inputfield value in module config #2010

Toutouwai opened this issue Aug 31, 2016 · 2 comments

Comments

@Toutouwai
Copy link

Toutouwai commented Aug 31, 2016

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).

@ryancramerdesign
Copy link
Owner

ryancramerdesign commented Aug 31, 2016

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).

@Toutouwai
Copy link
Author

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';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants