@@ -715,12 +715,18 @@ public function pre_deleteItem()
715715 'plugin_fields_containers_id ' => $ this ->fields ['id ' ],
716716 ]);
717717
718- //delete display condition
718+ //delete container display condition
719719 $ field_obj = new PluginFieldsContainerDisplayCondition ();
720720 $ field_obj ->deleteByCriteria ([
721721 'plugin_fields_containers_id ' => $ this ->fields ['id ' ],
722722 ]);
723723
724+ //delete field display condition
725+ $ field_obj = new PluginFieldsFieldDisplayCondition ();
726+ $ field_obj ->deleteByCriteria ([
727+ 'plugin_fields_fields_id ' => $ this ->fields ['id ' ],
728+ ]);
729+
724730 //delete profiles
725731 $ profile_obj = new PluginFieldsProfile ();
726732 $ profile_obj ->deleteByCriteria ([
@@ -1102,7 +1108,7 @@ public static function getEntries($type = 'tab', $full = false): array
11021108 }
11031109 }
11041110 }
1105-
1111+
11061112 return $ itemtypes ;
11071113 }
11081114
@@ -1202,12 +1208,12 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
12021208 *
12031209 * @return boolean
12041210 */
1205- public function updateFieldsValues ($ data , $ itemtype , $ massiveaction = false )
1211+ public function updateFieldsValues ($ data , $ item , $ massiveaction = false )
12061212 {
12071213 /** @var DBmysql $DB */
12081214 global $ DB ;
12091215
1210- if (self ::validateValues ($ data , $ itemtype , $ massiveaction ) === false ) {
1216+ if (self ::validateValues ($ data , $ item , $ massiveaction ) === false ) {
12111217 return false ;
12121218 }
12131219
@@ -1236,7 +1242,7 @@ public function updateFieldsValues($data, $itemtype, $massiveaction = false)
12361242 $ container_obj ->getFromDB ($ data ['plugin_fields_containers_id ' ]);
12371243
12381244 $ items_id = $ data ['items_id ' ];
1239- $ classname = self ::getClassname ($ itemtype , $ container_obj ->fields ['name ' ]);
1245+ $ classname = self ::getClassname ($ item -> getType () , $ container_obj ->fields ['name ' ]);
12401246
12411247 $ obj = new $ classname ();
12421248 if ($ obj ->getFromDBByCrit (['items_id ' => $ items_id ]) === false ) {
@@ -1255,7 +1261,7 @@ public function updateFieldsValues($data, $itemtype, $massiveaction = false)
12551261 self ::constructHistory (
12561262 $ obj ->input ['plugin_fields_containers_id ' ],
12571263 $ items_id ,
1258- $ itemtype ,
1264+ $ item -> getType () ,
12591265 $ obj ->input ,
12601266 $ obj ,
12611267 );
@@ -1442,7 +1448,7 @@ public static function constructHistory(
14421448 *
14431449 * @return boolean
14441450 */
1445- public static function validateValues ($ data , $ itemtype , $ massiveaction )
1451+ public static function validateValues ($ data , $ item , $ massiveaction )
14461452 {
14471453 /** @var DBmysql $DB */
14481454 global $ DB ;
@@ -1460,16 +1466,15 @@ public static function validateValues($data, $itemtype, $massiveaction)
14601466 ]);
14611467
14621468 $ status_value = null ;
1463- $ status_field_name = PluginFieldsStatusOverride::getStatusFieldName ($ itemtype );
1469+ $ status_field_name = PluginFieldsStatusOverride::getStatusFieldName ($ item -> getType () );
14641470 if ($ container ->fields ['type ' ] === 'dom ' ) {
14651471 $ status_value = $ data [$ status_field_name ] ?? null ;
14661472 } else {
1467- $ relatedItem = new $ itemtype ();
1468- $ status_value = $ relatedItem ->fields [$ status_field_name ] ?? null ;
1473+ $ status_value = $ item ->fields [$ status_field_name ] ?? null ;
14691474 }
14701475 // Apply status overrides
14711476 $ status_overrides = $ status_value !== null
1472- ? PluginFieldsStatusOverride::getOverridesForItemtypeAndStatus ($ container ->getID (), $ itemtype , $ status_value )
1477+ ? PluginFieldsStatusOverride::getOverridesForItemtypeAndStatus ($ container ->getID (), $ item -> getType () , $ status_value )
14731478 : [];
14741479
14751480 foreach ($ status_overrides as $ status_override ) {
@@ -1516,10 +1521,13 @@ public static function validateValues($data, $itemtype, $massiveaction)
15161521 //translate label
15171522 $ field ['itemtype ' ] = PluginFieldsField::getType ();
15181523 $ field ['label ' ] = PluginFieldsLabelTranslation::getLabelFor ($ field );
1519-
1524+
1525+ $ dc = new PluginFieldsFieldDisplayCondition ();
1526+
15201527 // Check mandatory fields
15211528 if (
15221529 $ field ['mandatory ' ] == 1
1530+ && $ dc ->computeDisplayField ($ item , $ field ['id ' ])
15231531 && (
15241532 empty ($ value )
15251533 || (($ field ['type ' ] === 'dropdown ' || preg_match ('/^dropdown-.+/i ' , $ field ['type ' ])) && $ value == 0 )
@@ -1620,7 +1628,7 @@ public static function postItemAdd(CommonDBTM $item)
16201628 $ data ['entities_id ' ] = $ item ->isEntityAssign () ? $ item ->getEntityID () : 0 ;
16211629 //update data
16221630 $ container = new self ();
1623- if ($ container ->updateFieldsValues ($ data , $ item-> getType () , isset ($ _REQUEST ['massiveaction ' ]))) {
1631+ if ($ container ->updateFieldsValues ($ data , $ item , isset ($ _REQUEST ['massiveaction ' ]))) {
16241632 return true ;
16251633 }
16261634
@@ -1724,7 +1732,7 @@ public static function preItem(CommonDBTM $item)
17241732 }
17251733
17261734 if (false !== ($ data = self ::populateData ($ c_id , $ item ))) {
1727- if (self ::validateValues ($ data , $ item:: getType () , isset ($ _REQUEST ['massiveaction ' ])) === false ) {
1735+ if (self ::validateValues ($ data , $ item , isset ($ _REQUEST ['massiveaction ' ])) === false ) {
17281736 $ item ->input = [];
17291737
17301738 return false ;
0 commit comments