diff --git a/CHANGELOG.md b/CHANGELOG.md index a57ea7bf..0c6c9009 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fix form submission error when a multiple dropdown field question is left empty - Fix search criterion value on multiple dropdown fields being reset after a search, which emptied the criterion when sorting or paging results +- Fix item clone failing when a mandatory GLPI item field is in an "Insert in form" block ## [1.24.7] - 2026-10-28 diff --git a/inc/container.class.php b/inc/container.class.php index a5a78af4..681e7fc7 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -2091,6 +2091,11 @@ public static function validateValues($data, $itemtype, $massiveaction, $is_crea $itemtype_key = sprintf('itemtype_%s', $name); $items_id_key = sprintf('items_id_%s', $name); + // not submitted during a massive action (ex: clone) as for the other field types + if ($massiveaction && !isset($data[$items_id_key])) { + continue; + } + $is_unchanged_reference = isset($stored_values[$itemtype_key], $stored_values[$items_id_key], $data[$itemtype_key], $data[$items_id_key]) && $stored_values[$itemtype_key] === $data[$itemtype_key] && (int) $stored_values[$items_id_key] === (int) $data[$items_id_key]; diff --git a/tests/Units/ContainerItemUpdateTest.php b/tests/Units/ContainerItemUpdateTest.php index 4888a513..75f4ff5d 100644 --- a/tests/Units/ContainerItemUpdateTest.php +++ b/tests/Units/ContainerItemUpdateTest.php @@ -41,6 +41,7 @@ use Entity; use Notification; use Problem; +use Supplier; require_once __DIR__ . '/../FieldTestCase.php'; @@ -1117,4 +1118,51 @@ public function testNotBlockedWhenMandatoryDomContainerIsHidden(): void ERROR, ); } + + public function testCloneThroughMassiveActionIsNotBlockedByMandatoryGlpiItemField(): void + { + $this->login(); + + $container = $this->createFieldContainer([ + 'label' => 'Mandatory GLPI item Clone Container', + 'type' => 'dom', + 'itemtypes' => [Computer::class], + 'is_active' => 1, + 'entities_id' => 0, + 'is_recursive' => 1, + ]); + $field = $this->createField([ + 'label' => 'Mandatory GLPI item', + 'type' => 'glpi_item', + PluginFieldsContainer::getForeignKeyField() => $container->getID(), + 'ranking' => 1, + 'is_active' => 1, + 'is_readonly' => 0, + 'mandatory' => 1, + 'allowed_values' => [Supplier::class], + ]); + $itemtype_key = 'itemtype_' . $field->fields['name']; + $items_id_key = 'items_id_' . $field->fields['name']; + + $supplier = $this->createItem(Supplier::class, [ + 'name' => 'Supplier for clone', + 'entities_id' => 0, + ]); + $computer = $this->createItem(Computer::class, [ + 'name' => 'Computer with mandatory GLPI item', + 'entities_id' => 0, + $itemtype_key => Supplier::class, + $items_id_key => $supplier->getID(), + ], [$itemtype_key, $items_id_key]); + + // The "Clone" massive action, also used from the item form, does not submit the plugin fields + $_REQUEST['massiveaction'] = 1; + try { + $clone_id = $computer->clone(); + } finally { + unset($_REQUEST['massiveaction']); + } + + $this->assertGreaterThan(0, $clone_id, 'Clone must not be blocked by a mandatory GLPI item field.'); + } }