diff --git a/CHANGELOG.md b/CHANGELOG.md index be1c398a..c63cbef4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +<<<<<<< HEAD ## [Unreleased] +======= +## [UNRELEASED] + +### Fixed + +- 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 +>>>>>>> 9101db6 (Fix/clone mandatory glpi item field (#1354)) ### Fixed diff --git a/inc/container.class.php b/inc/container.class.php index 5925314c..c2fa8c98 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 2b74ba03..708ec7df 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'; @@ -1120,4 +1121,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.'); + } }