Skip to content
Draft
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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
48 changes: 48 additions & 0 deletions tests/Units/ContainerItemUpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use Entity;
use Notification;
use Problem;
use Supplier;

require_once __DIR__ . '/../FieldTestCase.php';

Expand Down Expand Up @@ -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.');
}
}
Loading