Jump to content

Module configure field translation and field data not getting save


Zohaib-fk

Recommended Posts

Hi,

I want to add translation support for my field in configure area in module and services section.

I am using prestashop version 1.6.x and I made change as per other modules and below documentation link.

http://doc.prestashop.com/display/PS16/Making+your+module+work+with+Bootstrap

I am able to see field and multiple languages translation drop down option as per attach image.

But after saving field data not getting saved. It shows empty fields.

Below is my code.

PrestaShop Tutorials Videos [How to do Tasks]

 

public function renderForm()
    {
        $fields_form = array(
            'form' => array(
                'legend' => array(
                    'title' => $this->l('Settings'),
                    'icon' => 'icon-cogs'
                ),
                'input' => array(
                    array(
                        'type' => 'text',
                        'label' => $this->l('Block Title'),
                        'name' => 'BLOCK_TITLE',
                        'lang' => true,
                        'required' => true
                    ),
                    array(
                        'type' => 'text',
                        'label' => $this->l('Slide show time interval.'),
                        'name' => 'TIME_INTERVAL',
                        'hint' => $this->l('Only integer values allowed:'),
                        'desc' => $this->l('The interval in milli seconds example 8000.Only integer values allowed.'),
                        'lang' => true,
                        'required' => true
                    )
                ),
                'submit' => array(
                        'title' => $this->l('Save'),
                        'class' => 'btn btn-default pull-right'
                )
            ),
        );

        $helper = new HelperForm();
        $helper->show_toolbar = false;
        $helper->table =  $this->table;
        $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
        $helper->default_form_language = $lang->id;
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        $helper->identifier = $this->identifier;
        $helper->submit_action = 'submitStoreConf';
        $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->getConfigFieldsValues(),
                'languages' => $this->context->controller->getLanguages(),
                'id_language' => $this->context->language->id
        );

        return $helper->generateForm(array($fields_form));
    }
    
    public function getConfigFieldsValues()
    {
        $languages = Language::getLanguages(false);
        $fields = array();

        foreach ($languages as $lang)
        {
            $fields['BLOCK_TITLE'][$lang['id_lang']] = Tools::getValue('BLOCK_TITLE'.$lang['id_lang'], Configuration::get('BLOCK_TITLE', $lang['id_lang']));
            $fields['TIME_INTERVAL'][$lang['id_lang']] = Tools::getValue('TIME_INTERVAL'.$lang['id_lang'], Configuration::get('TIME_INTERVAL', $lang['id_lang']));
        }

        return $fields;
    }

Any idea to solve this problem.

 

 

 

Selection_012.png

Edited by Zohaib-fk
Post Updated (see edit history)
Link to comment
Share on other sites

  • 1 month later...

public function getContent()

    {

        $languages = Language::getLanguages(false);

        $output = null;

 

        if (Tools::isSubmit('submit'.$this->name)) {

            foreach ($languages as $lang)

            {

                $about[(int)$lang['id_lang']] = strval(Tools::getValue('ABOUT_'.(int)$lang['id_lang']));

            }

            

            if (!$about || empty($about)){

                $output .= $this->displayError($this->l('Invalid Configuration value'));

            } 

            else {

                Configuration::updateValue('ABOUT', $about);

            

                $output .= $this->displayConfirmation($this->l('Settings updated'));

            }

        }

        return $output.$this->displayForm();

    }

 

    public function displayForm()

    {

        $defaultLang = (int)Configuration::get('PS_LANG_DEFAULT');

    

        $fieldsForm[0]['form'] = [

            'legend' => [

                'title' => $this->l('Settings'),

                'icon' => 'icon-cogs'

            ],

            'input' => [

                

                [

                    'type' => 'textarea',

                    'label' => $this->l('About'),

                    'name' => 'ABOUT',

                    'lang' => true,

                    'required' => false,

                    'autoload_rte' => true,

                    'cols' => 60,

                    'rows' => 30

                ]

            ],

            'submit' => [

                'title' => $this->l('Save'),

                'class' => 'btn btn-default pull-right'

            ]

        ];

 

        $helper = new HelperForm();

 

        $helper->module = $this;

        $helper->name_controller = $this->name;

        $helper->token = Tools::getAdminTokenLite('AdminModules');

        $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;

        foreach (Language::getLanguages(false) as $lang)

            $helper->languages[] = array(

                'id_lang' => $lang['id_lang'],

                'iso_code' => $lang['iso_code'],

                'name' => $lang['name'],

                'is_default' => ($defaultLang == $lang['id_lang'] ? 1 : 0)

            );

        $helper->default_form_language = $defaultLang;

        $helper->allow_employee_form_lang = $defaultLang;

 

        $helper->title = $this->displayName;

        $helper->show_toolbar = true;        

        $helper->toolbar_scroll = true;      

        $helper->submit_action = 'submit'.$this->name;

        $helper->toolbar_btn = [

            'save' => [

                'desc' => $this->l('Save'),

                'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.

                '&token='.Tools::getAdminTokenLite('AdminModules'),

            ],

            'back' => [

                'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),

                'desc' => $this->l('Back to list')

            ]

        ];

 

        foreach (Language::getLanguages(false) as $lang) 

        {

            $helper->fields_value['ABOUT'][(int)$lang['id_lang']] = Tools::getValue('ABOUT_'.(int)$lang['id_lang'], Configuration::get('ABOUT', (int)$lang['id_lang']));

        }

       

        return $helper->generateForm($fieldsForm);

    }

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...