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 ''; + print $cssclassview ? '' : ''; print $valuetoshow; + print $cssclassview ? '' : ''; print ''; if (!$i) { diff --git a/htdocs/core/tpl/extrafields_list_search_input.tpl.php b/htdocs/core/tpl/extrafields_list_search_input.tpl.php index 7582f21e471..c7c6b2ec789 100644 --- a/htdocs/core/tpl/extrafields_list_search_input.tpl.php +++ b/htdocs/core/tpl/extrafields_list_search_input.tpl.php @@ -50,9 +50,11 @@ if (!empty($extrafieldsobjectkey)) { // $extrafieldsobject is the $object->table if ($extrafields->attributes[$extrafieldsobjectkey]['type'][$key] == 'separate') { continue; } - $cssclass = $extrafields->getAlignFlag($key, $extrafieldsobjectkey); + + $cssclasstd = $extrafields->getCSSClass($key, $extrafieldsobjectkey, 'csslist'); + $typeofextrafield = $extrafields->attributes[$extrafieldsobjectkey]['type'][$key]; - print ''; + print ''; $tmpkey = preg_replace('/'.$search_options_pattern.'/', '', $key); if (in_array($typeofextrafield, array('varchar', 'mail', 'ip', 'url', 'int', 'double')) && empty($extrafields->attributes[$extrafieldsobjectkey]['computed'][$key])) { $searchclass = ''; diff --git a/htdocs/core/tpl/extrafields_list_search_title.tpl.php b/htdocs/core/tpl/extrafields_list_search_title.tpl.php index b225d507022..1f2fa760e4d 100644 --- a/htdocs/core/tpl/extrafields_list_search_title.tpl.php +++ b/htdocs/core/tpl/extrafields_list_search_title.tpl.php @@ -1,5 +1,4 @@ * Copyright (C) 2025 Frédéric France * @@ -22,6 +21,11 @@ * @var Conf $conf * @var CommonObject $object * @var ?Translate $langs + * + * @var ?string $extrafieldsobjectkey + * @var ?int $disablesortlink + * @var string $sortfield + * @var string $sortorder */ // Protection to avoid direct call of template @@ -53,7 +57,8 @@ if (!empty($extrafieldsobjectkey)) { // $extrafieldsobject is the $object->table continue; } - $cssclass = $extrafields->getAlignFlag($key, $extrafieldsobjectkey); + $cssclasstd = $extrafields->getCSSClass($key, $extrafieldsobjectkey, 'csslist'); + $sortonfield = $extrafieldsobjectprefix.$key; if (!empty($extrafields->attributes[$extrafieldsobjectkey]['computed'][$key])) { $sortonfield = ''; @@ -66,7 +71,7 @@ if (!empty($extrafieldsobjectkey)) { // $extrafieldsobject is the $object->table $tooltip = empty($extrafields->attributes[$extrafieldsobjectkey]['help'][$key]) ? '' : $extrafields->attributes[$extrafieldsobjectkey]['help'][$key]; // Show cell - print getTitleFieldOfList($extrafields->attributes[$extrafieldsobjectkey]['label'][$key], 0, $_SERVER["PHP_SELF"], $sortonfield, "", $param, 'data-titlekey="'.$key.'"', $sortfield, $sortorder, $cssclass.' ', $disablesortlink, $tooltip)."\n"; + print getTitleFieldOfList($extrafields->attributes[$extrafieldsobjectkey]['label'][$key], 0, $_SERVER["PHP_SELF"], $sortonfield, "", $param, 'data-titlekey="'.$key.'"', $sortfield, $sortorder, $cssclassview.' ', $disablesortlink, $tooltip)."\n"; if (isset($totalarray) && isset($totalarray['nbfield'])) { $totalarray['nbfield']++; } diff --git a/htdocs/public/ticket/list.php b/htdocs/public/ticket/list.php index c835bdd1cf2..d769ac209a0 100644 --- a/htdocs/public/ticket/list.php +++ b/htdocs/public/ticket/list.php @@ -700,7 +700,7 @@ if ($action == "view_ticketlist") { foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { if (!empty($arrayfields["ef.".$key]['checked'])) { print 'getAlignFlag($key, $object->table_element); + $cssstring = $extrafields->getCSSClass($key, $object->table_element, 'csslist'); if ($cssstring) { print ' class="'.$cssstring.'"'; }