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 @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- 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
- Fix `Some mandatory fields are empty` error displayed when creating an item with an assigned technician
- Fix item clone failing when a mandatory dropdown field has an empty default value

## [1.24.7] - 2026-10-28

Expand Down
4 changes: 3 additions & 1 deletion inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2899,7 +2899,9 @@ private static function populateData($c_id, CommonDBTM $item)
}
} elseif ($item->isNewItem()) {
$default = PluginFieldsField::getDefaultValue($field);
if ($default !== null) {
// an empty dropdown default (0) is not a value, submitting it would fail a mandatory check (ex: clone)
$is_dropdown = $field['type'] === 'dropdown' || str_starts_with((string) $field['type'], 'dropdown-');
if ($default !== null && (!$is_dropdown || (int) $default !== 0)) {
$default_key = $field['type'] === 'dropdown'
? 'plugin_fields_' . $field['name'] . 'dropdowns_id'
: $field['name'];
Expand Down
85 changes: 85 additions & 0 deletions tests/Units/ContainerItemUpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
use GlpiPlugin\Field\Tests\FieldTestTrait;
use PluginFieldsContainer;
use PluginFieldsContainerDisplayCondition;
use PluginFieldsDropdown;
use Ticket;
use Entity;
use Location;
use Notification;
use Problem;
use Supplier;
Expand Down Expand Up @@ -1301,4 +1303,87 @@ public function testCloneThroughMassiveActionIsNotBlockedByMandatoryGlpiItemFiel

$this->assertGreaterThan(0, $clone_id, 'Clone must not be blocked by a mandatory GLPI item field.');
}

public function testCloneThroughMassiveActionIsNotBlockedByMandatoryDropdownWithEmptyDefault(): void
{
$this->login();

$container = $this->createFieldContainer([
'label' => 'Mandatory dropdown Clone Container',
'type' => 'dom',
'itemtypes' => [Computer::class],
'is_active' => 1,
'entities_id' => 0,
'is_recursive' => 1,
]);
$field = $this->createField([
'label' => 'Mandatory dropdown',
'type' => 'dropdown',
PluginFieldsContainer::getForeignKeyField() => $container->getID(),
'ranking' => 1,
'is_active' => 1,
'is_readonly' => 0,
'mandatory' => 1,
'default_value' => '0',
]);
$dropdown_key = 'plugin_fields_' . $field->fields['name'] . 'dropdowns_id';
$option = $this->createItem(PluginFieldsDropdown::getClassname($field->fields['name']), ['name' => 'Option']);

$computer = $this->createItem(Computer::class, [
'name' => 'Computer with mandatory dropdown',
'entities_id' => 0,
$dropdown_key => $option->getID(),
], [$dropdown_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 dropdown field with an empty default value.');
}

public function testCloneThroughMassiveActionIsNotBlockedByMandatoryItemtypeDropdownWithEmptyDefault(): void
{
$this->login();

$container = $this->createFieldContainer([
'label' => 'Itemtype dropdown Clone',
'type' => 'dom',
'itemtypes' => [Computer::class],
'is_active' => 1,
'entities_id' => 0,
'is_recursive' => 1,
]);
$field = $this->createField([
'label' => 'Mandatory itemtype dropdown',
'type' => 'dropdown-' . Location::class,
PluginFieldsContainer::getForeignKeyField() => $container->getID(),
'ranking' => 1,
'is_active' => 1,
'is_readonly' => 0,
'mandatory' => 1,
'default_value' => '0',
]);
$location = $this->createItem(Location::class, ['name' => 'Location for clone ' . random_int(1, PHP_INT_MAX), 'entities_id' => 0]);

$computer = $this->createItem(Computer::class, [
'name' => 'Computer with mandatory itemtype dropdown',
'entities_id' => 0,
$field->fields['name'] => $location->getID(),
], [$field->fields['name']]);

// 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 itemtype dropdown field with an empty default value.');
}
}
Loading