Moebius Posted February 11, 2019 Share Posted February 11, 2019 I'm trying to build custom form (module) and I want to make text fields multilanguage as they are in normal Processwire environment. This is some of code I have: <?php $form = $this->modules->get('InputfieldForm'); $field = $this->modules->get('InputfieldText'); $field->label = 'Title'; $field->name = 'title'; $field->columnWidth = 100; $field->required = 1; $fieldset->add($field); $form->add($fieldset); return $form->render(); ?> This is what I got: And this is what I want - with language switch at top: Is it possible to accomplish with API? Link to comment Share on other sites More sharing options...
dragan Posted February 11, 2019 Share Posted February 11, 2019 dobro vece ? I think you'll have to define your input field as type "TextareaLanguage" or "TextLanguage". And in your module use something like $field->label = _('Title'); 1 Link to comment Share on other sites More sharing options...
Moebius Posted February 11, 2019 Author Share Posted February 11, 2019 dobro vece dragane ? however, still no language switch at top. also tried with: $field->type = new FieldtypeTextLanguage(); but with no success. Link to comment Share on other sites More sharing options...
dragan Posted February 11, 2019 Share Posted February 11, 2019 Perhaps you'll need to uninstall and reinstall your module. Or click at the bottom button in modules > clear compiled files, to see your changes. Link to comment Share on other sites More sharing options...
OLSA Posted February 12, 2019 Share Posted February 12, 2019 Evo da se i ja ukljucim, rijetko sam ovdje ? There you need to include FieldtypeLanguageInterface, or if you watch at TextareaLanguage, or TextLanguage you will see this part in Fieldtype class: class FieldtypeTextareaLanguage extends FieldtypeTextarea implements FieldtypeLanguageInterface { ... or in TextLanguage class FieldtypeTextLanguage extends FieldtypeText implements FieldtypeLanguageInterface { After that, in Inputfield part you only need to use eg. textarea or text: class InputfieldMyNewField extends InputfieldTextarea { Inside ___render() part you do not need to include multilanguage input because PW magic will do the rest... Regards, Sasa Link to comment Share on other sites More sharing options...
Zeka Posted February 12, 2019 Share Posted February 12, 2019 @Moebius Try to set useLanguages property to true. $field->useLanguages = true; 3 Link to comment Share on other sites More sharing options...
Moebius Posted February 12, 2019 Author Share Posted February 12, 2019 Yes Zeka! That it solution. Now I see it in documentation, somehow lost between all other properties Thanks everyone for contribution. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now