Reputation: 361
I'm developing an prestashop module and it's just a beginning. The problem is in the configuration page of my module.
I append some text boxes and the label and description are visible, but the textbox is not visible.
I have looked many other examples but haven't found yet any differences and what is wrong.
Mystery is that if I change the type to date
or file
, it's visible.
// This function called in getContent() of main module php file.
public function displayForm()
{
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->trans('*'),
),
// Here is the textbox.
'input' => array(
array(
'type' => 'text',
'label' => $this->trans('Link:'),
'name' => 'LINK_PRODUCT',
'desc' => $this->trans('Please input the link...'),
'lang' => true,
'required' => true
)
),
'submit' => array(
'title' => $this->trans('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;
$helper->title = $this->displayName;
$helper->show_toolbar = false;
$helper->submit_action = 'submit';
$helper->fields_value['LINK_PRODUCT'] = Configuration::get('LINK_PRODUCT');
return $helper->generateForm(array($fields_form));
}
I would like to make the textbox visible, how should I go about doing this?
Upvotes: 0
Views: 1049
Reputation: 1814
You want to have multilingual so you need to define which language is a default. Add this code to your helper definition
$helper->default_form_language = $this->context->language->id;
and replace
$helper->fields_value['LINK_PRODUCT'] = Configuration::get('LINK_PRODUCT');
with
$helper->tpl_vars = array(
'fields_value' => array('LINK_PRODUCT' => Configuration::get('LINK_PRODUCT')),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
);
to define all available languages and values of your LINK_PRODUCT variable. And also, don't forget that you work with multilingual field and you need to have an array with values for your variable. So during extracting and saving you need to treat them as values for all languages. For example, if you have three languages available you need to get three values. The best way to get them is
$values = [];
foreach ($this->context->controller->getLanguages() as $language) {
$values[$language['id_lang']] = Configuration::get('LINK_PRODUCT', $language['id_lang']);
}
$helper->tpl_vars = array(
'fields_value' => array('LINK_PRODUCT' => $values),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
);
and when you will save it use similar combination but with updateValue
Upvotes: 2