inkredible Posted January 31, 2017 Posted January 31, 2017 Hey, I am writing a new application and I want to save "rules" as a setting using a decent editor. I have checked the IPS Chat application and I saw that you were using a "Translatable" so I tried to copy that idea. Unfortunately I am struggling with it. General information: My application is called: nodejschat My language key for this setting is: nodejschat_rulex_text My setting key is called: nodejschat_rules Saving and accessing two textfields (nodejschat_nodurl and nodejschat_nodeprivatekey) works without issues. I have created the setting "nodejschat_rules" in my developer center (along with other settings for this application). $form->add( new \IPS\Helpers\Form\Translatable( 'nodejschat_rules_text', NULL, FALSE, array( 'app' => 'nodejschat', 'key' => 'nodejschat_rules', 'editor' => array( 'app' => 'core', 'key' => 'Admin', 'autoSaveKey' => 'nodejschat_rules', 'attachIds' => array( NULL, NULL, 'nodejschat_rules' ) ) ), NULL, NULL, NULL, 'nodejschat_rules_id' ) ); if ( $values = $form->values() ) { \IPS\Lang::saveCustom( 'nodejschat', "nodejschat_rules", $values['nodejschat_rules'] ); unset( $values['nodejschat_rules'] ); $values['nodejschat_nodeurl'] = $values['nodejschat_nodeurl']; $values['nodejschat_nodeprivatekey'] = $values['nodejschat_nodeprivatekey']; $form->saveAsSettings( $values ); /* Clear guest page caches */ \IPS\Data\Cache::i()->clearAll(); } My problem(s): 1. It doesn't load the default value (which is "Don't spam!") into the editor 2. It doesn't save the content of my editor for the setting into the database 3. When trying around my "settings label" has been replaced by the editor's content (http://i.imgur.com/sPHELgS.png - the language key "nodejschat_rules_text" resolves to "Chat Rules"). I don't know where it is saved but I can't get rid of it. What am I doing wrong here?
bfarber Posted January 31, 2017 Posted January 31, 2017 Translatable fields won't be saved as a setting in the database (core_sys_conf_settings) - they are saved to language packs into core_sys_lang_words. As you saw, this is done in Chat so I would suggest just copying the methodology used there specifically. $form->add( new \IPS\Helpers\Form\Translatable( 'ipschat_rules_text', NULL, FALSE, array( 'app' => 'core', 'key' => 'ipschat_rules', 'editor' => array( 'app' => 'core', 'key' => 'Admin', 'autoSaveKey' => 'ipschat_rules', 'attachIds' => array( NULL, NULL, 'ipschat_rules' ) ) ), NULL, NULL, NULL, 'ipschat_rules_id' ) ); //.... \IPS\Lang::saveCustom( 'chat', "ipschat_rules", $values['ipschat_rules_text'] ); unset( $values['ipschat_rules_text'] ); 1) You should insert the default value (as a language string) during the application installation, which can be defined as part of the schema.json. If you look at our core application you'll see we insert "reg_rules_value" during the installation into the language strings table. 2) As I said, this will be saved as a language string so be sure you're looking in the right place. 3) I don't understand your last question here. What you are showing in the screenshot is the setting keywords option for developers to define keywords in order for administrators to find their settings with the ACP live search. It's not part of the editor and not something to get rid of.
inkredible Posted February 3, 2017 Author Posted February 3, 2017 Hey Brandon, thanks again for your answer, I am really thankful for the support given here. I think I have already copied the methodology and used exactly these lines with different variable names. I found the schema.json and the place where it would insert the reg_rules_value field, but now I wonder about the name. The translatable object uses "ipschat_rules_text" and "ipschat_rules" as variables, I don't see a reference to something called "reg_rules_value" in the modules\admin\chat\settings.php code.
bfarber Posted February 3, 2017 Posted February 3, 2017 Sorry, I used two different examples and merged them together in my response. ipschat_rules_text and reg_rules_value are references to two different settings (the latter relating to the registration terms and conditions setting).
inkredible Posted February 3, 2017 Author Posted February 3, 2017 2 hours ago, bfarber said: Sorry, I used two different examples and merged them together in my response. ipschat_rules_text and reg_rules_value are references to two different settings (the latter relating to the registration terms and conditions setting). I am sorry but I still wonder where the "ipschat_rules_text" is being created/saved. I searched the core's schema.json for the keyword 'chat' and the only field I found is "ignore_chats". The chat/data/schema.json does only create the chat_log_archive.
Daniel F Posted February 3, 2017 Posted February 3, 2017 Take a look at \IPS\Lang::saveCustom It's saved in the core_sys_lang_words table.
inkredible Posted February 4, 2017 Author Posted February 4, 2017 @Daniel F, I still don't get it. I got that the keyword will/should be saved in the core_sys_lang_words table, but my problem is that it doesn't work (probably just because I have no idea how to do it properly). In my initial post you can see my code which should be basically the same as your chat application, but it doesn't work. Hence I assume that there is something missing or wrong. Brandon's first answer completely confused me in the end :/. So another try: My application is called "nodejschat", and this is the related code for my Translatable: $form->add( new \IPS\Helpers\Form\Translatable( 'nodejschat_rules_label', NULL, FALSE, array( 'app' => 'nodejschat', 'key' => 'nodejschat_rules', 'editor' => array( 'app' => 'core', 'key' => 'Admin', 'autoSaveKey' => 'nodejschat_rules', 'attachIds' => array( NULL, NULL, 'nodejschat_rules' ) ) ), NULL, NULL, NULL, 'nodejschat_rules_id' ) ); if ( $values = $form->values() ) { \IPS\Lang::saveCustom( 'nodejschat', "nodejschat_rules", $values['nodejschat_rules'] ); unset( $values['nodejschat_rules'] ); } Because I couldn't find anything called "ipschat_rules" (from your chat) in the core's schema.json I assumed that you meant a language string which can be defined in the applications/nodejschat/dev/lang.php and I have added this line: 'nodejschat_rules' => "<p>Defaultcontent</p>", So can you explain again/in more detail what I need to do for creating my "nodejschat_rules" variable? In fact I found a row with the word_key "nodejschat_rules" in my core_sys_lang_words" table, but the "word_default" and "word_custom" field are null. When loading my translatable field it doesn't have predefined content. When I save content by myself it won't load afterwards either, which probably indicates that saving doesn't work either.
bfarber Posted February 6, 2017 Posted February 6, 2017 You shouldn't define the default language key (if you want to define the default text you should insert a row into core_sys_lang_words upon install of the application). Other than that I don't see any problems with what you are doing in your code snippets there and am not clear why you might have issues. I can only assume right now the reason you are having issues is because you have a default copy of the language string in place in your lang.php file which is overriding the custom value to be saved.
Flitterkill Posted February 13, 2017 Posted February 13, 2017 Small bump to this. What the others said is entirely correct. I'll just add that when you go to change this translatable bit via some application or plugin settings form in the ACP, if you have just a single language file installed it will display as a single text entry line. In order for the "translatable" nature of the field to become apparent, you need to have more than one language pack installed. In other words: One language pack installed: The form field will look like any other generic text entry form field. More than one language pack installed: Stacked text entry form fields with flags prefixed to indicate the language.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.