Search code examples
prestashopprestashop-1.6

Prestashop: HelperForm with multilang field


where I use Helperform. I want to make some fields translatable. I added the following form:

        $fields_form = array(
        'form' => array(
            'legend' => array(
                'title' => $this->l('Diplom hinzufügen'),
                'icon' => 'icon-question'
            ),
            'input' => array(
                array(
                    'type' => 'text',
                    'label' => $this->l('Name'),
                    'name' => 'name',
                    'lang' => true,
                ),
            ),
            'submit' => array('title' => $this->l('Save'))
        )
    );
    $helper = new HelperForm();
    $helper->submit_action = 'saveDiplom';
    $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
    $helper->token = Tools::getAdminTokenLite('AdminModules');


    $helper->tpl_vars = array(
        'fields_value' => array(
            'name' => '',
        ),
    );


    return $helper->generateForm(array($fields_form));

I don't see the "name" field in the backoffice. What is wrong? If I delete 'lang' => true it shows up. Is there any other setting needed (like in the constructor)?


Solution

  • This is a standard HelperForm initialization:

    $helper = new HelperForm();
    $helper->show_toolbar             = false;
    $helper->table                    = $this->table;
    $helper->module                   = $this;
    $helper->default_form_language    = $this->context->language->id;
    $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
    
    $helper->identifier    = $this->identifier;
    $helper->submit_action = 'submitNameOfModuleModule';
    $helper->currentIndex  = $this->context->link->getAdminLink('AdminModules', false)
                             . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
    $helper->token         = Tools::getAdminTokenLite('AdminModules');
    
    $helper->tpl_vars = array(
        'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs, in your case you have passed the array directly */
        'languages'    => $this->context->controller->getLanguages(),
        'id_language'  => $this->context->language->id,
    );
    

    I guess you forgot the 'languages' in the tpl_vars array and the id_language too.

    Maybe this link should be helpful.