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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,21 @@ 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
- 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
>>>>>>> 4215589 (fix clone mandatory dropdown empty default (#1357))

### Fixed

Expand Down
4 changes: 3 additions & 1 deletion inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2830,7 +2830,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
135 changes: 135 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;

Expand Down Expand Up @@ -1120,4 +1122,137 @@ public function testNotBlockedWhenMandatoryDomContainerIsHidden(): void
ERROR,
);
}
<<<<<<< HEAD
=======

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.');
}

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.');
}
>>>>>>> 4215589 (fix clone mandatory dropdown empty default (#1357))
}
Loading