Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 2 additions & 8 deletions inc/appliance.class.php

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both calls pass true for $strip_tags (which already runs Toolbox::stripTags() internally) and then wrap the result in Toolbox::stripTags() again. It's harmless (stripping twice is a no-op) but redundant ; every other call site strips tags exactly once. Drop the true argument on both lines, or drop the outer Toolbox::stripTags().

Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Appliance $item)
sprintf(
__s('%1$s: %2$s'),
'<b><i>' . __s('Group in charge of the hardware') . '</i></b>',
Toolbox::stripTags(Dropdown::getDropdownName(
'glpi_groups',
$item->fields['groups_id_tech'],
)),
Toolbox::stripTags(PluginPdfCommon::getGroupDisplayName($item->fields['groups_id_tech'] ?? [], true)),
),
);

Expand All @@ -183,10 +180,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Appliance $item)
sprintf(
__s('%1$s: %2$s'),
'<b><i>' . __s('Group') . '</i></b>',
Toolbox::stripTags(Dropdown::getDropdownName(
'glpi_groups',
$item->fields['groups_id'],
)),
Toolbox::stripTags(PluginPdfCommon::getGroupDisplayName($item->fields['groups_id'] ?? [], true)),
),
);

Expand Down
5 changes: 1 addition & 4 deletions inc/cartridgeitem.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, CartridgeItem $cartitem)
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group in charge of the hardware') . '</i></b>',
Dropdown::getDropdownName(
'glpi_groups',
$cartitem->fields['groups_id_tech'],
),
PluginPdfCommon::getGroupDisplayName($cartitem->fields['groups_id_tech'] ?? []),
),
);

Expand Down
28 changes: 23 additions & 5 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
Comment thread
Herafia marked this conversation as resolved.
$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);
Expand Down Expand Up @@ -509,10 +530,7 @@ public static function mainLine(PluginPdfSimplePDF $pdf, $item, $field)
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group in charge of the hardware') . '</i></b>',
Dropdown::getDropdownName(
'glpi_groups',
$item->fields['groups_id_tech'],
),
self::getGroupDisplayName($item->fields['groups_id_tech'] ?? []),
),
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
Expand Down
5 changes: 1 addition & 4 deletions inc/computer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Computer $computer)
'<b><i>' . sprintf(
__('%1$s: %2$s'),
__('Group') . '</i></b>',
Dropdown::getDropdownName(
'glpi_groups',
$computer->fields['groups_id'],
),
PluginPdfCommon::getGroupDisplayName($computer->fields['groups_id'] ?? []),
),
'<b><i>' . sprintf(__('%1$s: %2$s'), __('UUID') . '</i></b>', $computer->fields['uuid']),
);
Expand Down
5 changes: 1 addition & 4 deletions inc/consumableitem.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, ConsumableItem $consitem
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group in charge of the hardware') . '</i></b>',
Dropdown::getDropdownName(
'glpi_groups',
$consitem->fields['groups_id_tech'],
),
PluginPdfCommon::getGroupDisplayName($consitem->fields['groups_id_tech'] ?? []),
),
);

Expand Down
7 changes: 3 additions & 4 deletions inc/software.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Software $software)
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group in charge of the hardware') . '</i></b>',
Dropdown::getDropdownName(
'glpi_groups',
$software->fields['groups_id_tech'],
PluginPdfCommon::getGroupDisplayName(
$software->fields['groups_id_tech'] ?? [],
),
),
'<b><i>' . sprintf(
Expand All @@ -109,7 +108,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Software $software)
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group') . '</i></b>',
Dropdown::getDropdownName('glpi_groups', $software->fields['groups_id']),
PluginPdfCommon::getGroupDisplayName($software->fields['groups_id'] ?? []),
),
);

Expand Down