<![CDATA[ How to set the friendly name and description of system settings using code - MODX Community Forums]]> https://forums.modx.com/thread/?thread=104903 <![CDATA[How to set the friendly name and description of system settings using code]]> https://forums.modx.com/thread/104903/how-to-set-the-friendly-name-and-description-of-system-settings-using-code#dis-post-564071
I can create the setting with its key, type, value, namespace, and area settings with no problem and it shows up nicely in the Manager grid.

However, I can't set the name and description that appear in the Manager grid for users to tell them what these are. Looking at the MODX docs, that makes sense because these don't appear to be part of the modSystemSetting object, but I'm not clear how they actually do get set and stored. Is there a special method or a related object one has to work with? Can anyone help?

Here's the relevant code:

$newSettingProps=
	array(
	  'key' => 'new_setting',             //works
	  'name' => 'New Setting',            //THIS VALUE IS IGNORED
	  'description' => 'New Test Desc',   //THIS VALUE IS IGNORED
	  'xtype' =>  'combo-boolean',        //works
	  'namespace' => 'my_namespace',      //works
	  'area' => 'Test',                   //works
	  'value' => '1',                     //works
	);

$newSetting = $modx->newObject('modSystemSetting');
foreach ($newSettingProps as $key => $value) {
    $newSetting->set($key,$value);
}
$newSetting->save();


Thank you...]]>
alexepe Feb 13, 2019, 03:26 PM https://forums.modx.com/thread/104903/how-to-set-the-friendly-name-and-description-of-system-settings-using-code#dis-post-564071
<![CDATA[Re: How to set the friendly name and description of system settings using code]]> https://forums.modx.com/thread/104903/how-to-set-the-friendly-name-and-description-of-system-settings-using-code#dis-post-564095 Quote from: BobRay at Feb 14, 2019, 08:57 PM
Good catch. That's one of those things that should be handled with defaults in the processor, but isn't.

The user create processor is particularly bad about that. It requires you to set things like the password notification method and password selection method, even though you're not notifying the user and you've already sent it the password.

Thanks Bob. I often wish there was more explicit documentation of things like processors' expectations, but of course that all takes a lot of time to do...

I appreciate your help sorting this out. It had become a bit of a puzzle prior to your suggestions!]]>
alexepe Feb 15, 2019, 11:30 AM https://forums.modx.com/thread/104903/how-to-set-the-friendly-name-and-description-of-system-settings-using-code#dis-post-564095
<![CDATA[Re: How to set the friendly name and description of system settings using code]]> https://forums.modx.com/thread/104903/how-to-set-the-friendly-name-and-description-of-system-settings-using-code#dis-post-564092
The user create processor is particularly bad about that. It requires you to set things like the password notification method and password selection method, even though you're not notifying the user and you've already sent it the password.]]>
BobRay Feb 14, 2019, 08:57 PM https://forums.modx.com/thread/104903/how-to-set-the-friendly-name-and-description-of-system-settings-using-code#dis-post-564092
<![CDATA[Re: How to set the friendly name and description of system settings using code]]> https://forums.modx.com/thread/104903/how-to-set-the-friendly-name-and-description-of-system-settings-using-code#dis-post-564086 Quote from: BobRay at Feb 14, 2019, 04:04 AM
The name and description are lexicon strings, not object fields. They're set automatically by the modResourceCreateProcessor and the modResourceUpdateProcessor, but you bypass the processors when calling newObject() directly. You also bypass a bunch of sanity checks.

I think this will work to create a new setting properly, but I haven't tested it. Some processors can be picky about the fields they get.


Bob - Thank you very much - I hadn't twigged the names and descriptions were lexicon strings and hadn't thought of using a processor, but that feels like a better way to do things.

After a bit of experimentation, I found that one extra step is needed to persuade it to update the lexicon entries - in needs to be told which lexicon namespace and topic to use. So the following is the version that seems to work as desired:

$fields = array(
   'key' => 'new_setting',
   'name' => 'New Setting Name',
   'description' => 'New Setting Desc',
   'xtype' =>  'combo-boolean',
   'namespace' => 'my_namespace',
   'area' => 'Test',
   'value' => '1',
   'languageTopics' => array('my_chosen_namespace' => 'default'),
);
 
$modx->runProcessor('system/settings/create', $fields)


Many thanks!

Alex]]>
alexepe Feb 14, 2019, 03:21 PM https://forums.modx.com/thread/104903/how-to-set-the-friendly-name-and-description-of-system-settings-using-code#dis-post-564086
<![CDATA[Re: How to set the friendly name and description of system settings using code]]> https://forums.modx.com/thread/104903/how-to-set-the-friendly-name-and-description-of-system-settings-using-code#dis-post-564076
I think this will work to create a new setting properly, but I haven't tested it. Some processors can be picky about the fields they get.

$fields = array(
   'key' => 'new_setting',
   'name' => 'New Setting Name',
   'description' => 'New Setting Desc',
   'xtype' =>  'combo-boolean',
   'namespace' => 'my_namespace',
   'area' => 'Test',
   'value' => '1',
);

$modx->runProcessor('system/settings/create', $fields);

// to update an existing setting call the 'system/settings/update' processor.


]]>
BobRay Feb 14, 2019, 04:04 AM https://forums.modx.com/thread/104903/how-to-set-the-friendly-name-and-description-of-system-settings-using-code#dis-post-564076