33
33
// Minimal GLPI version, inclusive
34
34
define ("PLUGIN_FIELDS_MIN_GLPI " , "10.0.0 " );
35
35
// Maximum GLPI version, exclusive
36
- define ("PLUGIN_FIELDS_MAX_GLPI " , "10.0 .99 " );
36
+ define ("PLUGIN_FIELDS_MAX_GLPI " , "10.1 .99 " );
37
37
38
38
if (!defined ("PLUGINFIELDS_DIR " )) {
39
39
define ("PLUGINFIELDS_DIR " , Plugin::getPhpDir ("fields " ));
63
63
mkdir (PLUGINFIELDS_FRONT_PATH );
64
64
}
65
65
66
+ use Glpi \Plugin \Hooks ;
66
67
use Symfony \Component \Yaml \Yaml ;
67
68
68
69
/**
@@ -85,105 +86,109 @@ function plugin_init_fields()
85
86
$ pluginfields_autoloader = new PluginFieldsAutoloader ([PLUGINFIELDS_CLASS_PATH ]);
86
87
$ pluginfields_autoloader ->register ();
87
88
88
- if (Session::getLoginUserID () && Plugin::isPluginActive ('fields ' )) {
89
- // Init hook about itemtype(s) for plugin fields
90
- if (!isset ($ PLUGIN_HOOKS ['plugin_fields ' ])) {
91
- $ PLUGIN_HOOKS ['plugin_fields ' ] = [];
92
- }
89
+ if (Plugin::isPluginActive ('fields ' )) {
90
+ // This API integration cannot be done inside a login check since the plugin is initialized before the Router handles authentication
91
+ $ PLUGIN_HOOKS [Hooks::REDEFINE_API_SCHEMAS ]['fields ' ] = 'plugin_fields_redefine_api_schemas ' ;
92
+ if (Session::getLoginUserID ()) {
93
+ // Init hook about itemtype(s) for plugin fields
94
+ if (!isset ($ PLUGIN_HOOKS ['plugin_fields ' ])) {
95
+ $ PLUGIN_HOOKS ['plugin_fields ' ] = [];
96
+ }
93
97
94
- // When a Category is changed during ticket creation
95
- if (
96
- isset ($ _POST ) && !empty ($ _POST )
97
- && isset ($ _POST ['_plugin_fields_type ' ])
98
- && $ _SERVER ['REQUEST_URI ' ] ?? '' == Ticket::getFormURL ()
99
- ) {
100
- foreach ($ _POST as $ key => $ value ) {
101
- if (!is_array ($ value )) {
102
- $ _SESSION ['plugin ' ]['fields ' ]['values_sent ' ][$ key ] = $ value ;
98
+ // When a Category is changed during ticket creation
99
+ if (
100
+ isset ($ _POST ) && !empty ($ _POST )
101
+ && isset ($ _POST ['_plugin_fields_type ' ])
102
+ && $ _SERVER ['REQUEST_URI ' ] ?? '' == Ticket::getFormURL ()
103
+ ) {
104
+ foreach ($ _POST as $ key => $ value ) {
105
+ if (!is_array ($ value )) {
106
+ $ _SESSION ['plugin ' ]['fields ' ]['values_sent ' ][$ key ] = $ value ;
107
+ }
103
108
}
104
109
}
105
- }
106
110
107
- if (Plugin::isPluginActive ('fusioninventory ' )) {
108
- $ PLUGIN_HOOKS ['fusioninventory_inventory ' ]['fields ' ]
109
- = ['PluginFieldsInventory ' , 'updateInventory ' ];
110
- }
111
+ if (Plugin::isPluginActive ('fusioninventory ' )) {
112
+ $ PLUGIN_HOOKS ['fusioninventory_inventory ' ]['fields ' ]
113
+ = ['PluginFieldsInventory ' , 'updateInventory ' ];
114
+ }
111
115
112
- // complete rule engine
113
- $ PLUGIN_HOOKS ['use_rules ' ]['fields ' ] = ['PluginFusioninventoryTaskpostactionRule ' ];
114
- $ PLUGIN_HOOKS ['rule_matched ' ]['fields ' ] = 'plugin_fields_rule_matched ' ;
116
+ // complete rule engine
117
+ $ PLUGIN_HOOKS ['use_rules ' ]['fields ' ] = ['PluginFusioninventoryTaskpostactionRule ' ];
118
+ $ PLUGIN_HOOKS ['rule_matched ' ]['fields ' ] = 'plugin_fields_rule_matched ' ;
115
119
116
- if (isset ($ _SESSION ['glpiactiveentities ' ])) {
117
- // add link in plugin page
118
- $ PLUGIN_HOOKS ['config_page ' ]['fields ' ] = 'front/container.php ' ;
120
+ if (isset ($ _SESSION ['glpiactiveentities ' ])) {
121
+ // add link in plugin page
122
+ $ PLUGIN_HOOKS ['config_page ' ]['fields ' ] = 'front/container.php ' ;
119
123
120
- // add entry to configuration menu
121
- $ PLUGIN_HOOKS ["menu_toadd " ]['fields ' ] = ['config ' => 'PluginFieldsMenu ' ];
124
+ // add entry to configuration menu
125
+ $ PLUGIN_HOOKS ["menu_toadd " ]['fields ' ] = ['config ' => 'PluginFieldsMenu ' ];
122
126
123
- // add tabs to itemtypes
124
- $ itemtypes = array_unique (PluginFieldsContainer::getEntries ());
125
- if (count ($ itemtypes ) > 0 ) {
126
- Plugin::registerClass (
127
- 'PluginFieldsContainer ' ,
128
- ['addtabon ' => $ itemtypes ]
129
- );
130
- }
127
+ // add tabs to itemtypes
128
+ $ itemtypes = array_unique (PluginFieldsContainer::getEntries ());
129
+ if (count ($ itemtypes ) > 0 ) {
130
+ Plugin::registerClass (
131
+ 'PluginFieldsContainer ' ,
132
+ ['addtabon ' => $ itemtypes ]
133
+ );
134
+ }
131
135
132
- //include js and css
133
- $ debug = (isset ($ _SESSION ['glpi_use_mode ' ])
134
- && $ _SESSION ['glpi_use_mode ' ] == Session::DEBUG_MODE ? true : false );
135
- if (!$ debug && file_exists (__DIR__ . '/css/fields.min.css ' )) {
136
- $ PLUGIN_HOOKS ['add_css ' ]['fields ' ][] = 'css/fields.min.css ' ;
137
- } else {
138
- $ PLUGIN_HOOKS ['add_css ' ]['fields ' ][] = 'css/fields.css ' ;
139
- }
136
+ //include js and css
137
+ $ debug = (isset ($ _SESSION ['glpi_use_mode ' ])
138
+ && $ _SESSION ['glpi_use_mode ' ] == Session::DEBUG_MODE ? true : false );
139
+ if (!$ debug && file_exists (__DIR__ . '/css/fields.min.css ' )) {
140
+ $ PLUGIN_HOOKS ['add_css ' ]['fields ' ][] = 'css/fields.min.css ' ;
141
+ } else {
142
+ $ PLUGIN_HOOKS ['add_css ' ]['fields ' ][] = 'css/fields.css ' ;
143
+ }
140
144
141
- // Add/delete profiles to automaticaly to container
142
- $ PLUGIN_HOOKS ['item_add ' ]['fields ' ]['Profile ' ] = ["PluginFieldsProfile " , "addNewProfile " ];
143
- $ PLUGIN_HOOKS ['pre_item_purge ' ]['fields ' ]['Profile ' ] = ["PluginFieldsProfile " , "deleteProfile " ];
145
+ // Add/delete profiles to automaticaly to container
146
+ $ PLUGIN_HOOKS ['item_add ' ]['fields ' ]['Profile ' ] = ["PluginFieldsProfile " , "addNewProfile " ];
147
+ $ PLUGIN_HOOKS ['pre_item_purge ' ]['fields ' ]['Profile ' ] = ["PluginFieldsProfile " , "deleteProfile " ];
144
148
145
- //load drag and drop javascript library on Package Interface
146
- $ PLUGIN_HOOKS ['add_javascript ' ]['fields ' ][] = "lib/redips-drag-min.js " ;
147
- if (!$ debug && file_exists (__DIR__ . '/js/drag-field-row.min.js ' )) {
148
- $ PLUGIN_HOOKS ['add_javascript ' ]['fields ' ][] = 'js/drag-field-row.min.js ' ;
149
- } else {
150
- $ PLUGIN_HOOKS ['add_javascript ' ]['fields ' ][] = 'js/drag-field-row.js ' ;
149
+ //load drag and drop javascript library on Package Interface
150
+ $ PLUGIN_HOOKS ['add_javascript ' ]['fields ' ][] = "lib/redips-drag-min.js " ;
151
+ if (!$ debug && file_exists (__DIR__ . '/js/drag-field-row.min.js ' )) {
152
+ $ PLUGIN_HOOKS ['add_javascript ' ]['fields ' ][] = 'js/drag-field-row.min.js ' ;
153
+ } else {
154
+ $ PLUGIN_HOOKS ['add_javascript ' ]['fields ' ][] = 'js/drag-field-row.js ' ;
155
+ }
151
156
}
152
- }
153
157
154
- // Add Fields to Datainjection
155
- if (Plugin::isPluginActive ('datainjection ' )) {
156
- $ PLUGIN_HOOKS ['plugin_datainjection_populate ' ]['fields ' ] = "plugin_datainjection_populate_fields " ;
157
- }
158
+ // Add Fields to Datainjection
159
+ if (Plugin::isPluginActive ('datainjection ' )) {
160
+ $ PLUGIN_HOOKS ['plugin_datainjection_populate ' ]['fields ' ] = "plugin_datainjection_populate_fields " ;
161
+ }
158
162
159
- //Retrieve dom container
160
- $ itemtypes = PluginFieldsContainer::getUsedItemtypes ();
161
- if ($ itemtypes !== false ) {
162
- foreach ($ itemtypes as $ itemtype ) {
163
- $ PLUGIN_HOOKS ['pre_item_update ' ]['fields ' ][$ itemtype ] = [
164
- "PluginFieldsContainer " ,
165
- "preItemUpdate "
166
- ];
167
- $ PLUGIN_HOOKS ['pre_item_add ' ]['fields ' ][$ itemtype ] = [
168
- "PluginFieldsContainer " ,
169
- "preItem "
170
- ];
171
- $ PLUGIN_HOOKS ['item_add ' ]['fields ' ][$ itemtype ] = [
172
- "PluginFieldsContainer " ,
173
- "postItemAdd "
174
- ];
175
- $ PLUGIN_HOOKS ['pre_item_purge ' ] ['fields ' ][$ itemtype ] = [
176
- "PluginFieldsContainer " ,
177
- "preItemPurge "
178
- ];
163
+ //Retrieve dom container
164
+ $ itemtypes = PluginFieldsContainer::getUsedItemtypes ();
165
+ if ($ itemtypes !== false ) {
166
+ foreach ($ itemtypes as $ itemtype ) {
167
+ $ PLUGIN_HOOKS ['pre_item_update ' ]['fields ' ][$ itemtype ] = [
168
+ "PluginFieldsContainer " ,
169
+ "preItemUpdate "
170
+ ];
171
+ $ PLUGIN_HOOKS ['pre_item_add ' ]['fields ' ][$ itemtype ] = [
172
+ "PluginFieldsContainer " ,
173
+ "preItem "
174
+ ];
175
+ $ PLUGIN_HOOKS ['item_add ' ]['fields ' ][$ itemtype ] = [
176
+ "PluginFieldsContainer " ,
177
+ "postItemAdd "
178
+ ];
179
+ $ PLUGIN_HOOKS ['pre_item_purge ' ] ['fields ' ][$ itemtype ] = [
180
+ "PluginFieldsContainer " ,
181
+ "preItemPurge "
182
+ ];
183
+ }
179
184
}
180
- }
181
185
182
- // Display fields in any existing tab
183
- $ PLUGIN_HOOKS ['post_item_form ' ]['fields ' ] = [
184
- 'PluginFieldsField ' ,
185
- 'showForTab '
186
- ];
186
+ // Display fields in any existing tab
187
+ $ PLUGIN_HOOKS ['post_item_form ' ]['fields ' ] = [
188
+ 'PluginFieldsField ' ,
189
+ 'showForTab '
190
+ ];
191
+ }
187
192
}
188
193
}
189
194
0 commit comments