@@ -440,6 +440,34 @@ public function prepareInputForAdd($input) {
440440 }
441441 }
442442
443+ // handle description field and its inline pictures
444+ if (isset ($ input ['_description ' ])) {
445+ foreach ($ input ['_description ' ] as $ id => $ filename ) {
446+ // TODO :replace PluginFormcreatorCommon::getDuplicateOf by Document::getDuplicateOf
447+ // when is merged https://github.com/glpi-project/glpi/pull/9335
448+ if ($ document = PluginFormcreatorCommon::getDuplicateOf (Session::getActiveEntity (), GLPI_TMP_DIR . '/ ' . $ filename )) {
449+ $ this ->value = str_replace ('id=" ' . $ input ['_tag_description ' ] . '" ' , $ document ->fields ['tag ' ], $ this ->value );
450+ $ input ['_tag_description ' ][$ id ] = $ document ->fields ['tag ' ];
451+ }
452+ }
453+
454+ $ input = $ this ->addFiles (
455+ $ input ,
456+ [
457+ 'force_update ' => true ,
458+ 'content_field ' => null ,
459+ 'name ' => 'description ' ,
460+ ]
461+ );
462+
463+ $ input ['description ' ] = Html::entity_decode_deep ($ input ['description ' ]);
464+ foreach ($ input ['_tag_description ' ] as $ tag ) {
465+ $ regex = '/<img[^>]+ ' . preg_quote ($ tag , '/ ' ) . '[^<]+>/im ' ;
466+ $ input ['description ' ] = preg_replace ($ regex , "# $ tag# " , $ input ['description ' ]);
467+ }
468+ $ input ['description ' ] = Html::entities_deep ($ input ['description ' ]);
469+ }
470+
443471 // generate a unique id
444472 if (!isset ($ input ['uuid ' ])
445473 || empty ($ input ['uuid ' ])) {
@@ -469,6 +497,34 @@ public function prepareInputForUpdate($input) {
469497 return false ;
470498 }
471499
500+ // handle description field and its inline pictures
501+ if (isset ($ input ['_description ' ])) {
502+ foreach ($ input ['_description ' ] as $ id => $ filename ) {
503+ // TODO :replace PluginFormcreatorCommon::getDuplicateOf by Document::getDuplicateOf
504+ // when is merged https://github.com/glpi-project/glpi/pull/9335
505+ if ($ document = PluginFormcreatorCommon::getDuplicateOf (Session::getActiveEntity (), GLPI_TMP_DIR . '/ ' . $ filename )) {
506+ $ this ->value = str_replace ('id=" ' . $ input ['_tag_description ' ] . '" ' , $ document ->fields ['tag ' ], $ this ->value );
507+ $ input ['_tag_description ' ][$ id ] = $ document ->fields ['tag ' ];
508+ }
509+ }
510+
511+ $ input = $ this ->addFiles (
512+ $ input ,
513+ [
514+ 'force_update ' => true ,
515+ 'content_field ' => null ,
516+ 'name ' => 'description ' ,
517+ ]
518+ );
519+
520+ $ input ['description ' ] = Html::entity_decode_deep ($ input ['description ' ]);
521+ foreach ($ input ['_tag_description ' ] as $ tag ) {
522+ $ regex = '/<img[^>]+ ' . preg_quote ($ tag , '/ ' ) . '[^<]+>/im ' ;
523+ $ input ['description ' ] = preg_replace ($ regex , "# $ tag# " , $ input ['description ' ]);
524+ }
525+ $ input ['description ' ] = Html::entities_deep ($ input ['description ' ]);
526+ }
527+
472528 // generate a unique id
473529 if (!isset ($ input ['uuid ' ])
474530 || empty ($ input ['uuid ' ])) {
@@ -831,7 +887,7 @@ public function showForm($ID, $options = []) {
831887 echo Html::textarea ([
832888 'name ' => 'description ' ,
833889 'id ' => 'description ' ,
834- 'value ' => $ this ->fields ['description ' ],
890+ 'value ' => Toolbox:: convertTagToImage ( $ this ->fields ['description ' ], $ this ) ,
835891 'enable_richtext ' => true ,
836892 'filecontainer ' => 'description_info ' ,
837893 'display ' => false ,
0 commit comments