diff --git a/src/ContentTemplates/Parameters/TicketParameters.php b/src/ContentTemplates/Parameters/TicketParameters.php index 7e3fe3b6dc0..f40409f9ce8 100644 --- a/src/ContentTemplates/Parameters/TicketParameters.php +++ b/src/ContentTemplates/Parameters/TicketParameters.php @@ -138,7 +138,7 @@ protected function defineValues(CommonDBTM $ticket): array $kbis = KnowbaseItem_Item::getItems($ticket); $values['knowbaseitems'] = []; foreach ($kbis as $data) { - if ($kbi = KnowbaseItem::getById($data['id'])) { + if ($kbi = KnowbaseItem::getById($data[KnowbaseItem::getForeignKeyField()])) { $kbi_parameters = new KnowbaseItemParameters(); $values['knowbaseitems'][] = $kbi_parameters->getValues($kbi); } diff --git a/tests/functional/Glpi/ContentTemplates/Parameters/TicketParameters.php b/tests/functional/Glpi/ContentTemplates/Parameters/TicketParameters.php index b40a65d28e1..3dae1bb70e6 100644 --- a/tests/functional/Glpi/ContentTemplates/Parameters/TicketParameters.php +++ b/tests/functional/Glpi/ContentTemplates/Parameters/TicketParameters.php @@ -97,7 +97,7 @@ public function testGetValues(): void $suppliers_id = getItemByTypeName('Supplier', '_suplier01_name', true); $now = date('Y-m-d H:i:s'); - $this->createItem('Ticket', [ + $created_ticket = $this->createItem('Ticket', [ 'name' => 'ticket_testGetValues', 'content' => '
ticket_testGetValues content
', 'entities_id' => $test_entity_id, @@ -114,8 +114,13 @@ public function testGetValues(): void '_groups_id_assign' => [$assigned_groups_id], '_suppliers_id_assign' => [$suppliers_id], ]); + $tickets_id = $created_ticket->getID(); - $tickets_id = getItemByTypeName('Ticket', 'ticket_testGetValues', true); + $this->createItem(\KnowbaseItem_Item::class, [ + 'knowbaseitems_id' => getItemByTypeName(\KnowbaseItem::class, '_knowbaseitem01', true), + 'itemtype' => 'Ticket', + 'items_id' => $tickets_id, + ]); $parameters = $this->newTestedInstance(); $values = $parameters->getValues(getItemByTypeName('Ticket', 'ticket_testGetValues')); @@ -247,7 +252,14 @@ public function testGetValues(): void 'name' => 'location_testGetValues', 'completename' => 'location_testGetValues', ], - 'knowbaseitems' => [], + 'knowbaseitems' => [ + [ + 'id' => getItemByTypeName(\KnowbaseItem::class, '_knowbaseitem01', true), + 'name' => '_knowbaseitem01', + 'answer' => "Answer for Knowledge base entry _knowbaseitem01 apple juice turnover", + 'link' => "_knowbaseitem01" + ] + ], 'assets' => [], ]);