Moebius Posted February 11, 2019 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?
dragan Posted February 11, 2019 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
Moebius Posted February 11, 2019 Author 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.
dragan Posted February 11, 2019 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.
OLSA Posted February 12, 2019 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
Zeka Posted February 12, 2019 Posted February 12, 2019 @Moebius Try to set useLanguages property to true. $field->useLanguages = true; 3
Moebius Posted February 12, 2019 Author 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.
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