39
39
use Toolbox ;
40
40
use Session ;
41
41
use DBUtils ;
42
+ use Document ;
42
43
use Dropdown ;
43
44
use CommonITILActor ;
44
45
use CommonITILObject ;
62
63
use Glpi \Application \View \TemplateRenderer ;
63
64
class DropdownField extends PluginFormcreatorAbstractField
64
65
{
65
-
66
66
const ENTITY_RESTRICT_USER = 1 ;
67
67
const ENTITY_RESTRICT_FORM = 2 ;
68
68
const ENTITY_RESTRICT_BOTH = 3 ;
69
69
70
+ protected static $ noEntityRrestrict = [Entity::class, Document::class];
71
+
70
72
public function getEnumEntityRestriction () {
71
73
return [
72
74
self ::ENTITY_RESTRICT_USER => User::getTypeName (1 ),
@@ -94,10 +96,14 @@ public function showForm(array $options): void {
94
96
$ this ->question ->fields ['_entity_restrict ' ] = $ decodedValues ['entity_restrict ' ] ?? self ::ENTITY_RESTRICT_FORM ;
95
97
$ this ->question ->fields ['_is_tree ' ] = '0 ' ;
96
98
$ this ->question ->fields ['_is_entity_restrict ' ] = '0 ' ;
99
+ if (isset ($ this ->question ->fields ['itemtype ' ]) && is_subclass_of ($ this ->question ->fields ['itemtype ' ], CommonDBTM::class)) {
100
+ if (!in_array ($ this ->question ->fields ['itemtype ' ], self ::$ noEntityRrestrict )) {
101
+ $ item = new $ this ->question ->fields ['itemtype ' ];
102
+ $ this ->question ->fields ['_is_entity_restrict ' ] = $ item ->isEntityAssign () ? '1 ' : '0 ' ;
103
+ }
104
+ }
97
105
if (isset ($ this ->question ->fields ['itemtype ' ]) && is_subclass_of ($ this ->question ->fields ['itemtype ' ], CommonTreeDropdown::class)) {
98
106
$ this ->question ->fields ['_is_tree ' ] = '1 ' ;
99
- $ item = new $ this ->question ->fields ['itemtype ' ];
100
- $ this ->question ->fields ['_is_entity_restrict ' ] = $ item ->isEntityAssign () ? '1 ' : '0 ' ;
101
107
}
102
108
$ this ->question ->fields ['default_values ' ] = Html::entities_deep ($ this ->question ->fields ['default_values ' ]);
103
109
$ this ->deserializeValue ($ this ->question ->fields ['default_values ' ]);
@@ -136,6 +142,10 @@ public function buildParams($rand = null) {
136
142
JSON_OBJECT_AS_ARRAY
137
143
);
138
144
145
+ if (in_array ($ itemtype , self ::$ noEntityRrestrict )) {
146
+ unset($ dparams ['entity ' ]);
147
+ }
148
+
139
149
switch ($ itemtype ) {
140
150
case SLA ::class:
141
151
case OLA ::class:
@@ -145,11 +155,6 @@ public function buildParams($rand = null) {
145
155
}
146
156
break ;
147
157
148
- case Entity::class:
149
- case Document::class:
150
- unset($ dparams ['entity ' ]);
151
- break ;
152
-
153
158
case User::class:
154
159
$ dparams ['right ' ] = 'all ' ;
155
160
$ currentEntity = Session::getActiveEntity ();
0 commit comments