@@ -191,6 +191,15 @@ public function serializeValue(PluginFormcreatorFormAnswer $formanswer): string
191
191
$ key = 'formcreator_field_ ' . $ this ->question ->getID ();
192
192
if (isset ($ this ->uploads ['_ ' . $ key ])) {
193
193
$ input = [$ key => $ this ->value ] + $ this ->uploads ;
194
+ // for each uploaded document, check if it already exists in DB
195
+ foreach ($ this ->uploads ['_tag_ ' . $ key ] as $ docKey => $ tag ) {
196
+ $ document = new Document ();
197
+ $ newTag = $ tag ;
198
+ if ($ document ->getDuplicateOf ($ formanswer ->fields ['entities_id ' ], GLPI_TMP_DIR . '/ ' . $ input ['_ ' . $ key ][$ docKey ])) {
199
+ $ newTag = $ document ->fields ['tag ' ];
200
+ }
201
+ $ this ->uploads ['dedup ' ][$ tag ] = $ newTag ;
202
+ }
194
203
$ input = $ formanswer ->addFiles (
195
204
$ input ,
196
205
[
@@ -203,11 +212,7 @@ public function serializeValue(PluginFormcreatorFormAnswer $formanswer): string
203
212
// $this->value = $input[$key];
204
213
$ this ->value = Sanitizer::unsanitize ($ this ->value );
205
214
foreach ($ input ['_tag ' ] as $ docKey => $ tag ) {
206
- $ document = new Document ();
207
- $ newTag = $ tag ;
208
- if ($ document ->getDuplicateOf ($ formanswer ->fields ['entities_id ' ], GLPI_TMP_DIR . '/ ' . $ input ['_ ' . $ key ][$ docKey ])) {
209
- $ newTag = $ document ->fields ['tag ' ];
210
- }
215
+ $ newTag = $ this ->uploads ['dedup ' ][$ tag ];
211
216
$ regex = '/<img[^>]+ ' . preg_quote ($ tag , '/ ' ) . '[^<]+>/im ' ;
212
217
$ this ->value = preg_replace ($ regex , "# $ newTag# " , $ this ->value );
213
218
}
0 commit comments