4040use Toolbox ;
4141use Session ;
4242use DBUtils ;
43+ use Document ;
4344use Dropdown ;
4445use CommonGLPI ;
4546use CommonITILActor ;
6768
6869class DropdownField extends PluginFormcreatorAbstractField
6970{
70-
7171 const ENTITY_RESTRICT_USER = 1 ;
7272 const ENTITY_RESTRICT_FORM = 2 ;
7373 const ENTITY_RESTRICT_BOTH = 3 ;
7474
75+ protected static $ noEntityRrestrict = [Entity::class, Document::class];
76+
7577 public function getEnumEntityRestriction () {
7678 return [
7779 self ::ENTITY_RESTRICT_USER => User::getTypeName (1 ),
@@ -133,10 +135,14 @@ public function showForm(array $options): void {
133135 $ this ->question ->fields ['_entity_restrict ' ] = $ decodedValues ['entity_restrict ' ] ?? self ::ENTITY_RESTRICT_FORM ;
134136 $ this ->question ->fields ['_is_tree ' ] = '0 ' ;
135137 $ this ->question ->fields ['_is_entity_restrict ' ] = '0 ' ;
138+ if (isset ($ this ->question ->fields ['itemtype ' ]) && is_subclass_of ($ this ->question ->fields ['itemtype ' ], CommonDBTM::class)) {
139+ if (!in_array ($ this ->question ->fields ['itemtype ' ], self ::$ noEntityRrestrict )) {
140+ $ item = new $ this ->question ->fields ['itemtype ' ];
141+ $ this ->question ->fields ['_is_entity_restrict ' ] = $ item ->isEntityAssign () ? '1 ' : '0 ' ;
142+ }
143+ }
136144 if (isset ($ this ->question ->fields ['itemtype ' ]) && is_subclass_of ($ this ->question ->fields ['itemtype ' ], CommonTreeDropdown::class)) {
137145 $ this ->question ->fields ['_is_tree ' ] = '1 ' ;
138- $ item = new $ this ->question ->fields ['itemtype ' ];
139- $ this ->question ->fields ['_is_entity_restrict ' ] = $ item ->isEntityAssign () ? '1 ' : '0 ' ;
140146 }
141147 $ this ->question ->fields ['default_values ' ] = Html::entities_deep ($ this ->question ->fields ['default_values ' ]);
142148 $ this ->deserializeValue ($ this ->question ->fields ['default_values ' ]);
@@ -176,6 +182,10 @@ public function buildParams($rand = null) {
176182 JSON_OBJECT_AS_ARRAY
177183 );
178184
185+ if (in_array ($ itemtype , self ::$ noEntityRrestrict )) {
186+ unset($ dparams ['entity ' ]);
187+ }
188+
179189 switch ($ itemtype ) {
180190 case SLA ::class:
181191 case OLA ::class:
@@ -185,11 +195,6 @@ public function buildParams($rand = null) {
185195 }
186196 break ;
187197
188- case Entity::class:
189- case Document::class:
190- unset($ dparams ['entity ' ]);
191- break ;
192-
193198 case User::class:
194199 $ dparams ['right ' ] = 'all ' ;
195200 $ currentEntity = Session::getActiveEntity ();
@@ -1019,7 +1024,7 @@ protected function getEntityRestriction() {
10191024 switch ($ restrictionPolicy ) {
10201025 case self ::ENTITY_RESTRICT_FORM :
10211026 $ form = PluginFormcreatorForm::getByItem ($ this ->getQuestion ());
1022- $ formEntities = [$ form ->fields ['entities_id ' ]];
1027+ $ formEntities = [$ form ->fields ['entities_id ' ] => $ form -> fields [ ' entities_id ' ] ];
10231028 if ($ form ->fields ['is_recursive ' ]) {
10241029 $ formEntities = $ formEntities + (new DBUtils ())->getSonsof (Entity::getTable (), $ form ->fields ['entities_id ' ]);
10251030 }
@@ -1028,7 +1033,7 @@ protected function getEntityRestriction() {
10281033
10291034 case self ::ENTITY_RESTRICT_BOTH :
10301035 $ form = PluginFormcreatorForm::getByItem ($ this ->getQuestion ());
1031- $ formEntities = [$ form ->fields ['entities_id ' ]];
1036+ $ formEntities = [$ form ->fields ['entities_id ' ] => $ form -> fields [ ' entities_id ' ] ];
10321037 if ($ form ->fields ['is_recursive ' ]) {
10331038 $ formEntities = $ formEntities + (new DBUtils ())->getSonsof (Entity::getTable (), $ form ->fields ['entities_id ' ]);
10341039 }
0 commit comments