diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c48cc26..3982e895 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fix dependency conflict with GLPI core by no longer vendoring symfony/deprecation-contracts and symfony/polyfill-ctype. - Fix default field values not being applied when fields are empty on creation - Fix mandatory fields blocking automated item creation +- Fix unclear mandatory field error when a GLPI form creating a ticket does not provide the field. ## [1.24.5] - 2026-09-11 diff --git a/inc/container.class.php b/inc/container.class.php index 45afb6ed..9969c275 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -1669,10 +1669,11 @@ private static function isMandatoryCheckBypassed(array $data): bool * @param array $data Data send by form * @param string $itemtype Item type * @param boolean $massiveaction ? + * @param boolean $is_creation True when validating a new item with nothing submitted * * @return boolean */ - public static function validateValues($data, $itemtype, $massiveaction) + public static function validateValues($data, $itemtype, $massiveaction, $is_creation = false) { /** @var DBmysql $DB */ global $DB; @@ -1775,6 +1776,13 @@ public static function validateValues($data, $itemtype, $massiveaction) if ($empty_errors !== []) { Session::AddMessageAfterRedirect(__('Some mandatory fields are empty', 'fields') . ' : ' . implode(', ', $empty_errors), false, ERROR); + if ($is_creation) { + Session::AddMessageAfterRedirect( + __('The form or source creating this item does not provide the mandatory fields above: map them to it, or make them optional.', 'fields'), + false, + ERROR, + ); + } } if ($number_errors !== []) { @@ -2061,7 +2069,7 @@ private static function checkContainerMandatory(CommonDBTM $item, PluginFieldsCo } } - if (self::validateValues($data, $item::getType(), isset($_REQUEST['massiveaction'])) === false) { + if (self::validateValues($data, $item::getType(), isset($_REQUEST['massiveaction']), $item->isNewItem()) === false) { return false; } diff --git a/tests/Units/ContainerItemUpdateTest.php b/tests/Units/ContainerItemUpdateTest.php index 760ce33e..90367905 100644 --- a/tests/Units/ContainerItemUpdateTest.php +++ b/tests/Units/ContainerItemUpdateTest.php @@ -355,6 +355,10 @@ public function testCreateIsBlockedWhenMandatoryDomFieldIsMissing(): void __('Some mandatory fields are empty', 'fields'), ERROR, ); + $this->hasSessionMessageThatContains( + __('The form or source creating this item does not provide the mandatory fields above: map them to it, or make them optional.', 'fields'), + ERROR, + ); // Creation with the mandatory field filled must succeed. $ticket = new Ticket();