diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 3313aa39bc7..9954624538e 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -2438,8 +2438,22 @@ class ExtraFields * @param string $key Key of attribute * @param string $extrafieldsobjectkey If defined, use the new method to get extrafields data * @return string Formatted value + * @deprecated Use getCSSClass() */ public function getAlignFlag($key, $extrafieldsobjectkey = '') + { + return $this->getCSSClass($key, $extrafieldsobjectkey); + } + + /** + * Return the CSS to use for this extrafield into list + * + * @param string $key Key of attribute + * @param string $extrafieldsobjectkey If defined, use the new method to get extrafields data + * @param string $mode 'csslist' (used on td into table list), 'css' (used on create/update), 'cssview' (used on view) + * @return string Formatted value + */ + public function getCSSClass($key, $extrafieldsobjectkey = '', $mode = 'csslist') { $type = 'varchar'; if (!empty($extrafieldsobjectkey)) { @@ -2448,19 +2462,27 @@ class ExtraFields $cssstring = ''; - if (in_array($type, array('date', 'datetime', 'datetimegmt',))) { - $cssstring = "center"; - } elseif (in_array($type, array('int', 'price', 'double', 'duration'))) { - $cssstring = "right"; - } elseif (in_array($type, array('boolean', 'radio', 'checkbox', 'ip', 'icon'))) { - $cssstring = "center"; + if ($mode == 'csslist') { + if (in_array($type, array('date', 'datetime', 'datetimegmt',))) { + $cssstring = "center"; + } elseif (in_array($type, array('int', 'price', 'double', 'duration'))) { + $cssstring = "right"; + } elseif (in_array($type, array('boolean', 'radio', 'checkbox', 'ip', 'icon'))) { + $cssstring = "center"; + } + + if (!empty($this->attributes[$extrafieldsobjectkey][$mode][$key])) { + $cssstring .= ($cssstring ? ' ' : '').$this->attributes[$extrafieldsobjectkey][$mode][$key]; + } else { + if (in_array($type, array('ip'))) { + $cssstring .= ($cssstring ? ' ' : '').'tdoverflowmax150'; + } + } } - if (!empty($this->attributes[$extrafieldsobjectkey]['csslist'][$key])) { - $cssstring .= ($cssstring ? ' ' : '').$this->attributes[$extrafieldsobjectkey]['csslist'][$key]; - } else { - if (in_array($type, array('ip'))) { - $cssstring .= ($cssstring ? ' ' : '').'tdoverflowmax150'; + if ($mode == 'css' || $mode == 'cssview') { + if (!empty($this->attributes[$extrafieldsobjectkey][$mode][$key])) { + $cssstring = ($cssstring ? ' ' : '').$this->attributes[$extrafieldsobjectkey][$mode][$key]; } } diff --git a/htdocs/core/tpl/extrafields_list_print_fields.tpl.php b/htdocs/core/tpl/extrafields_list_print_fields.tpl.php index e7fb7e0ac2b..63421ff9021 100644 --- a/htdocs/core/tpl/extrafields_list_print_fields.tpl.php +++ b/htdocs/core/tpl/extrafields_list_print_fields.tpl.php @@ -45,7 +45,8 @@ if (!empty($extrafieldsobjectkey) && !empty($extrafields->attributes[$extrafield continue; } - $cssclass = $extrafields->getAlignFlag($key, $extrafieldsobjectkey); + $cssclasstd = $extrafields->getCSSClass($key, $extrafieldsobjectkey, 'csslist'); + $cssclassview = $extrafields->getCSSClass($key, $extrafieldsobjectkey, 'cssview'); $tmpkey = 'options_'.$key; @@ -64,7 +65,7 @@ if (!empty($extrafieldsobjectkey) && !empty($extrafields->attributes[$extrafield } // If field is a computed field, we make computation to get value if ($extrafields->attributes[$extrafieldsobjectkey]['computed'][$key]) { - $objectoffield = $object; //For compatibility with the computed formula + $objectoffield = $object; // For compatibility with the computed formula $value = dol_eval((string) $extrafields->attributes[$extrafieldsobjectkey]['computed'][$key], 1, 1, '2'); if (is_numeric(price2num($value)) && $extrafields->attributes[$extrafieldsobjectkey]['totalizable'][$key]) { $obj->$tmpkey = price2num($value); @@ -74,11 +75,13 @@ if (!empty($extrafieldsobjectkey) && !empty($extrafields->attributes[$extrafield $valuetoshow = $extrafields->showOutputField($key, $value, '', $extrafieldsobjectkey, null, $object); $title = dol_string_nohtmltag($valuetoshow); - print '