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

[DX] Form API: Allow specifying alternative configuration settings for elements using system_settings_form(), without having to use custom submit handler #4102

Open
klonos opened this issue Sep 28, 2019 · 3 comments

Comments

@klonos
Copy link
Member

klonos commented Sep 28, 2019

In https://api.backdropcms.org/api/backdrop/1/search/system_settings_form it mentions how you can specify a different config file for some of the form elements/values via '#config'. What do you do though if you want to save to the same top-level '#config', but to a different setting?

So say that your form element is $form['my']['cool']['element'] = array( ... ); but you want the setting to be saved as my_cool_element in the .json? ...is a custom submit handler the only option in that case?

So basically, I understand that you can do this:

$primary_config = config('mymodule.settings');
$secondary_config = config('mymodule.moar.settings');

$form = array('#config' => 'mymodule.settings');

$form['first_setting'] = array( ... );
$form['second_setting'] = array(
  ...
  '#config' => 'mymodule.moar.settings',
  ...
);

...and that this saves first_setting in mymodule.settings.json, while second_setting is saved in mymodule.moar.settings.json.

What I need to do though is something like this:

$config = config('mymodule.settings');

$form = array('#config' => 'mymodule.settings');

$form['first_setting'] = array( ... );
$form['second_setting'] = array(
  ...
  '#config_setting' => 'call_this_something_else',
  ...
);

...so both settings will be saved in the same mymodule.settings.json file. The first one as "first_setting", while the second one as "call_this_something_else". So instead of this:

{
    "_config_name": "mymodule.settings",
    "_module": "mymodule",
    "first_setting": 123,
    "second_setting": "abc",
}

...I would instead want to have this:

{
    "_config_name": "mymodule.settings",
    "_module": "mymodule",
    "first_setting": 123,
    "call_this_something_else": "abc",
}
@klonos
Copy link
Member Author

klonos commented Sep 28, 2019

PS: is it '#default_setting' (like in that api.b.org page), or is it '#default_value'?

@klonos klonos closed this as completed Sep 28, 2019
@klonos klonos reopened this Sep 28, 2019
@ghost
Copy link

ghost commented Mar 30, 2022

...is a custom submit handler the only option in that case?

AFAIK, yes.

@klonos klonos changed the title [DX] How to specify alternative configuration settings for elements using system_settings_form()? [DX] Form API: Allow specifying alternative configuration settings for elements using system_settings_form(), without having to use custom submit handler Dec 26, 2022
@klonos klonos self-assigned this Dec 26, 2022
@klonos
Copy link
Member Author

klonos commented Dec 26, 2022

Right. I'm making this a feature request then 😉

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

1 participant