2016-03-07 36 views
1

這裏我看到一個小問題,我有兩個表模板和template_text,在模板表中我存儲模板類型和可見性數據,並在template_text表中存儲多種語言的模板文本atm 。我有兩個朗。如EN和DE。所以,當我編輯模板時,我將當前模板值預先加載到表單中,但autoemailer_title和autoemailer_body等值存在問題,當從幫助器生成表單字段時,它將以這種方式生成此字段autoemailer_title_1,autoemailer_title_2語言ID,那麼,問題將是如何預先加載所有這些值的正確方法?我可以使用javascript和ajax獲取請求來獲取值,然後使用輸入ID設置它們,但我認爲使用表單助手有更好的方法。PrestaShop FormHelper預加載多語言值

$fields_form = array(
      'form' => array(
       'legend' => array(
        'title' => $this->l($params['title']), 
        'icon' => 'icon-cogs' 
       ), 
       'input' => array(
        array(
         'type' => 'select',        // This is a <select> tag. 
         'label' => $this->l('Template type'),   // The <label> for this <select> tag. 
         'desc' => $this->l('Choose a template type'), // A help text, displayed right next to the <select> tag. 
         'name' => 'autoemailer_type',      // The content of the 'id' attribute of the <select> tag. 
         'required' => true,        // If set to true, this option must be set. 
         'options' => array(
          'query' => array(
           array(
            'id_option' => 'static',  // The value of the 'value' attribute of the <option> tag. 
            'name' => 'Static' // The value of the text content of the <option> tag. 
           ), 
           array(
            'id_option' => 'dynamic', 
            'name' => 'Dynamic' 
           ), 
          ),       // $options contains the data itself. 
          'id' => 'id_option',       // The value of the 'id' key must be the same as the key for 'value' attribute of the <option> tag in each $options sub-array. 
          'name' => 'name'        // The value of the 'name' key must be the same as the key for the text content of the <option> tag in each $options sub-array. 
         ) 
        ), 
        array(
         'type' => 'text', 
         'label' => $this->l('News letter title'), 
         'name' => 'autoemailer_title', 
         'desc' => $this->l('Title'), 
         'lang' => true, 
         // 'style' => 'width:300px', 
         'class' => 'fixed-width-lg', 
        ), 
        array(
         'type' => 'textarea', 
         'label' => $this->l('Text'), 
         'name' => 'autoemailer_body', 
         'desc' => $this->l('Email body'), 
         'lang' => true, 
         'cols' => 60, 
         'rows' => 10, 
         'class' => 'rte', // we need this for setuping the tiny mce editor 
         'autoload_rte' => true, // we need this for setuping the tiny mce editor 
        ), 
       ), 
       'submit' => array(
        'title' => $this->l('Save') 
       ) 
      ) 
     ); 

     $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; 
     $this->fields_form = array(); 

     $helper->identifier = $this->identifier; 
     $helper->submit_action = 'newTemplate'; 
     $helper->currentIndex = $this->getThisUrl() . '&emailer_action=main'; 
     $helper->token = Tools::getAdminTokenLite('AdminModules'); 

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

如果您使用' HelperForm'類在其已定義的情況下 - 所有的值,包括多語言值,都已經爲您預加載。你遇到什麼問題? –

+0

實際上沒有問題,只是在爲multilang設置默認值時遇到了一個小問題。屬性,但解決它很快:) –

回答

1

解決了這個問題。因此,當我們有多個lang時,那麼我們應用multilangiage選項的屬性將成爲一個數組,因此要根據語言設置值,我們可以這樣做:

$lang_id = 1; // setting the language ID, usually it's done by foreaching the records from ps_lang table 

$helper->fields_value['description'][$lang_id] = 'my default value'; // setting the default value 

return $helper->generateForm(array($fields_form)); // returning the output of generated form