diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f42bf7..051c4d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fix image (field : description) in to pdf - Fix massive action PDF export redirecting to item list instead of generating the PDF +- Fix group and group technician display name ## [4.1.2] - 2026-01-08 diff --git a/inc/appliance.class.php b/inc/appliance.class.php index bbee4b1..7cdd9cd 100644 --- a/inc/appliance.class.php +++ b/inc/appliance.class.php @@ -154,10 +154,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Appliance $item) sprintf( __s('%1$s: %2$s'), '' . __s('Group in charge of the hardware') . '', - Toolbox::stripTags(Dropdown::getDropdownName( - 'glpi_groups', - $item->fields['groups_id_tech'], - )), + Toolbox::stripTags(PluginPdfCommon::getGroupDisplayName($item->fields['groups_id_tech'] ?? [], true)), ), ); @@ -183,10 +180,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Appliance $item) sprintf( __s('%1$s: %2$s'), '' . __s('Group') . '', - Toolbox::stripTags(Dropdown::getDropdownName( - 'glpi_groups', - $item->fields['groups_id'], - )), + Toolbox::stripTags(PluginPdfCommon::getGroupDisplayName($item->fields['groups_id'] ?? [], true)), ), ); diff --git a/inc/cartridgeitem.class.php b/inc/cartridgeitem.class.php index 63a09db..b1977b9 100644 --- a/inc/cartridgeitem.class.php +++ b/inc/cartridgeitem.class.php @@ -95,10 +95,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, CartridgeItem $cartitem) '' . sprintf( __s('%1$s: %2$s'), __s('Group in charge of the hardware') . '', - Dropdown::getDropdownName( - 'glpi_groups', - $cartitem->fields['groups_id_tech'], - ), + PluginPdfCommon::getGroupDisplayName($cartitem->fields['groups_id_tech'] ?? []), ), ); diff --git a/inc/common.class.php b/inc/common.class.php index a883614..b48dbe9 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -59,7 +59,7 @@ public function addStandardTab($itemtype, array &$ong, array $options) $withtemplate = $options['withtemplate']; } - if (!is_numeric($itemtype) && ($obj = $dbu->getItemForItemtype($itemtype)) && (method_exists($itemtype, 'displayTabContentForPDF'))) { + if (($obj = $dbu->getItemForItemtype($itemtype)) && (method_exists($itemtype, 'displayTabContentForPDF'))) { $titles = $obj->getTabNameForItem($this->obj, $withtemplate); if (!is_array($titles)) { $titles = [1 => $titles]; @@ -420,6 +420,27 @@ final public function generatePDF($tab_id, $tabs, $page = 0, $render = true) } } + // This helper accepts both formats: the old one (int) and the new one (array). + //This is for compatibility with other item types that do not use the AssignableItem trait. + public static function getGroupDisplayName(array|int $group_ids, bool $strip_tags = false): string + { + if (!is_array($group_ids)) { + $group_ids = $group_ids > 0 ? [$group_ids] : []; + } + $group_ids = array_filter(array_map('intval', $group_ids), static fn($id) => $id > 0); + if ($group_ids === []) { + $name = Dropdown::getDropdownName('glpi_groups', 0); + return $strip_tags ? Toolbox::stripTags($name) : $name; + } + $names = array_map( + static fn($id) => $strip_tags + ? Toolbox::stripTags(Dropdown::getDropdownName('glpi_groups', $id)) + : Dropdown::getDropdownName('glpi_groups', $id), + $group_ids, + ); + return implode(', ', $names); + } + public static function mainTitle(PluginPdfSimplePDF $pdf, $item) { $pdf->setColumnsSize(50, 50); @@ -509,10 +530,7 @@ public static function mainLine(PluginPdfSimplePDF $pdf, $item, $field) '' . sprintf( __s('%1$s: %2$s'), __s('Group in charge of the hardware') . '', - Dropdown::getDropdownName( - 'glpi_groups', - $item->fields['groups_id_tech'], - ), + self::getGroupDisplayName($item->fields['groups_id_tech'] ?? []), ), '' . sprintf( __s('%1$s: %2$s'), diff --git a/inc/computer.class.php b/inc/computer.class.php index c8851cf..57e103e 100644 --- a/inc/computer.class.php +++ b/inc/computer.class.php @@ -89,10 +89,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Computer $computer) '' . sprintf( __('%1$s: %2$s'), __('Group') . '', - Dropdown::getDropdownName( - 'glpi_groups', - $computer->fields['groups_id'], - ), + PluginPdfCommon::getGroupDisplayName($computer->fields['groups_id'] ?? []), ), '' . sprintf(__('%1$s: %2$s'), __('UUID') . '', $computer->fields['uuid']), ); diff --git a/inc/consumableitem.class.php b/inc/consumableitem.class.php index 991a641..9461fcc 100644 --- a/inc/consumableitem.class.php +++ b/inc/consumableitem.class.php @@ -84,10 +84,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, ConsumableItem $consitem '' . sprintf( __s('%1$s: %2$s'), __s('Group in charge of the hardware') . '', - Dropdown::getDropdownName( - 'glpi_groups', - $consitem->fields['groups_id_tech'], - ), + PluginPdfCommon::getGroupDisplayName($consitem->fields['groups_id_tech'] ?? []), ), ); diff --git a/inc/software.class.php b/inc/software.class.php index 21a3526..6432b95 100644 --- a/inc/software.class.php +++ b/inc/software.class.php @@ -93,9 +93,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Software $software) '' . sprintf( __s('%1$s: %2$s'), __s('Group in charge of the hardware') . '', - Dropdown::getDropdownName( - 'glpi_groups', - $software->fields['groups_id_tech'], + PluginPdfCommon::getGroupDisplayName( + $software->fields['groups_id_tech'] ?? [], ), ), '' . sprintf( @@ -109,7 +108,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Software $software) '' . sprintf( __s('%1$s: %2$s'), __s('Group') . '', - Dropdown::getDropdownName('glpi_groups', $software->fields['groups_id']), + PluginPdfCommon::getGroupDisplayName($software->fields['groups_id'] ?? []), ), );