Fix translation of extrafields

This commit is contained in:
Laurent Destailleur 2018-04-17 13:52:50 +02:00
parent 7b53ec5198
commit 7bb8078b46

View File

@ -839,9 +839,10 @@ class ExtraFields
* @param string $keyprefix Suffix string to add before name and id of field (can be used to avoid duplicate names) * @param string $keyprefix Suffix string to add before name and id of field (can be used to avoid duplicate names)
* @param string $morecss More css (to defined size of field. Old behaviour: may also be a numeric) * @param string $morecss More css (to defined size of field. Old behaviour: may also be a numeric)
* @param int $objectid Current object id * @param int $objectid Current object id
* @param string $extrafieldsobjectkey If defined (for example $object->table_element), use the new method to get extrafields data
* @return string * @return string
*/ */
function showInputField($key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss='', $objectid=0) function showInputField($key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss='', $objectid=0, $extrafieldsobjectkey='')
{ {
global $conf,$langs,$form; global $conf,$langs,$form;
@ -855,6 +856,23 @@ class ExtraFields
$keyprefix = $keyprefix.'options_'; // Because we work on extrafields $keyprefix = $keyprefix.'options_'; // Because we work on extrafields
if (! empty($extrafieldsobjectkey))
{
$label=$this->attributes[$extrafieldsobjectkey]['label'][$key];
$type=$this->attributes[$extrafieldsobjectkey]['type'][$key];
$size=$this->attributes[$extrafieldsobjectkey]['size'][$key];
$default=$this->attributes[$extrafieldsobjectkey]['default'][$key];
$computed=$this->attributes[$extrafieldsobjectkey]['computed'][$key];
$unique=$this->attributes[$extrafieldsobjectkey]['unique'][$key];
$required=$this->attributes[$extrafieldsobjectkey]['required'][$key];
$param=$this->attributes[$extrafieldsobjectkey]['param'][$key];
$perms=dol_eval($this->attributes[$extrafieldsobjectkey]['perms'][$key], 1);
$langfile=$this->attributes[$extrafieldsobjectkey]['langfile'][$key];
$list=dol_eval($this->attributes[$extrafieldsobjectkey]['list'][$key], 1);
$hidden=(empty($list) ? 1 : 0); // If empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller)
}
else // Old usage
{
$label=$this->attribute_label[$key]; $label=$this->attribute_label[$key];
$type =$this->attribute_type[$key]; $type =$this->attribute_type[$key];
$size =$this->attribute_size[$key]; $size =$this->attribute_size[$key];
@ -867,6 +885,7 @@ class ExtraFields
$langfile=$this->attribute_langfile[$key]; $langfile=$this->attribute_langfile[$key];
$list=$this->attribute_list[$key]; $list=$this->attribute_list[$key];
$hidden=$this->attribute_hidden[$key]; $hidden=$this->attribute_hidden[$key];
}
if ($computed) if ($computed)
{ {
@ -1008,7 +1027,10 @@ class ExtraFields
$out.='<option value="'.$key.'"'; $out.='<option value="'.$key.'"';
$out.= (((string) $value == (string) $key)?' selected':''); $out.= (((string) $value == (string) $key)?' selected':'');
$out.= (!empty($parent)?' parent="'.$parent.'"':''); $out.= (!empty($parent)?' parent="'.$parent.'"':'');
$out.='>'.$val.'</option>'; $out.='>';
if ($langfile) $out.=$langs->trans($val);
else $out.=$val;
$out.='</option>';
} }
$out.='</select>'; $out.='</select>';
} }
@ -1470,7 +1492,8 @@ class ExtraFields
} }
elseif ($type == 'select') elseif ($type == 'select')
{ {
$value=$param['options'][$value]; if ($langfile) $value=$langs->trans($param['options'][$value]);
else $value=$param['options'][$value];
} }
elseif ($type == 'sellist') elseif ($type == 'sellist')
{ {