diff --git a/src/Ticket.php b/src/Ticket.php index 230ce200cca..baec13f9afd 100644 --- a/src/Ticket.php +++ b/src/Ticket.php @@ -4319,6 +4319,31 @@ public function showForm($ID, array $options = []) } } + // Default check + if ($ID > 0) { + $this->check($ID, READ); + } else { + // Create item + $this->check(-1, CREATE, $options); + } + + $userentities = []; + if (!$ID) { + $userentities = $this->getEntitiesForRequesters($options); + + if ( + count($userentities) > 0 + && !in_array($this->fields["entities_id"], $userentities) + ) { + // If entity is not in the list of user's entities, + // then use as default value the first value of the user's entites list + $first_entity = current($userentities); + $this->fields["entities_id"] = $first_entity; + // Pass to values + $options['entities_id'] = $first_entity; + } + } + // Check category / type validity if ($options['itilcategories_id']) { $cat = new ITILCategory(); @@ -4326,7 +4351,7 @@ public function showForm($ID, array $options = []) switch ($options['type']) { case self::INCIDENT_TYPE: if (!$cat->getField('is_incident')) { - $options['itilcategories_id'] = 0; + $options['itilcategories_id'] = 0; } break; @@ -4342,35 +4367,11 @@ public function showForm($ID, array $options = []) // Check category / entity validity if (!in_array($cat->fields['entities_id'], getSonsOf('glpi_entities', $options['entities_id']))) { $options['itilcategories_id'] = 0; + $this->fields['itilcategories_id'] = 0; } } } - // Default check - if ($ID > 0) { - $this->check($ID, READ); - } else { - // Create item - $this->check(-1, CREATE, $options); - } - - $userentities = []; - if (!$ID) { - $userentities = $this->getEntitiesForRequesters($options); - - if ( - count($userentities) > 0 - && !in_array($this->fields["entities_id"], $userentities) - ) { - // If entity is not in the list of user's entities, - // then use as default value the first value of the user's entites list - $first_entity = current($userentities); - $this->fields["entities_id"] = $first_entity; - // Pass to values - $options['entities_id'] = $first_entity; - } - } - if ($options['type'] <= 0) { $options['type'] = Entity::getUsedConfig( 'tickettype',