Skip to content

Commit 0d78db1

Browse files
authored
fix(textarea, entityconfig): embedded image question description (#2901)
1 parent 552e495 commit 0d78db1

File tree

2 files changed

+62
-45
lines changed

2 files changed

+62
-45
lines changed

inc/entityconfig.class.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,28 @@ protected static function createDefaultsForEntity($entityId): self {
213213
return $entityConfig;
214214
}
215215

216+
public function post_addItem() {
217+
$this->input = $this->addFiles(
218+
$this->input,
219+
[
220+
'force_update' => true,
221+
'content_field' => 'header',
222+
'name' => 'header',
223+
]
224+
);
225+
}
226+
227+
public function post_updateItem($history = 1) {
228+
$this->input = $this->addFiles(
229+
$this->input,
230+
[
231+
'force_update' => true,
232+
'content_field' => 'header',
233+
'name' => 'header',
234+
]
235+
);
236+
}
237+
216238
public function showFormForEntity(Entity $entity) {
217239
$entityId = $entity->getID();
218240
if (!$entity->can($entityId, READ)) {

inc/question.class.php

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -427,33 +427,6 @@ public function prepareInputForAdd($input) {
427427
}
428428
}
429429

430-
// handle description field and its inline pictures
431-
if (isset($input['_description'])) {
432-
foreach ($input['_description'] as $id => $filename) {
433-
$document = new Document();
434-
if ($document->getDuplicateOf(Session::getActiveEntity(), GLPI_TMP_DIR . '/' . $filename)) {
435-
$this->value = str_replace('id="' . $input['_tag_description'] . '"', $document->fields['tag'], $this->value);
436-
$input['_tag_description'][$id] = $document->fields['tag'];
437-
}
438-
}
439-
440-
$input = $this->addFiles(
441-
$input,
442-
[
443-
'force_update' => true,
444-
'content_field' => null,
445-
'name' => 'description',
446-
]
447-
);
448-
449-
$input['description'] = Html::entity_decode_deep($input['description']);
450-
foreach ($input['_tag_description'] as $tag) {
451-
$regex = '/<img[^>]+' . preg_quote($tag, '/') . '[^<]+>/im';
452-
$input['description'] = preg_replace($regex, "#$tag#", $input['description']);
453-
}
454-
$input['description'] = Html::entities_deep($input['description']);
455-
}
456-
457430
// generate a unique id
458431
if (!isset($input['uuid'])
459432
|| empty($input['uuid'])) {
@@ -490,23 +463,6 @@ public function prepareInputForUpdate($input) {
490463
return false;
491464
}
492465

493-
// handle description field and its inline pictures
494-
if (isset($input['_description'])) {
495-
foreach ($input['_description'] as $id => $filename) {
496-
// TODO :replace PluginFormcreatorCommon::getDuplicateOf by Document::getDuplicateOf
497-
// when is merged https://github.com/glpi-project/glpi/pull/9335
498-
if ($document = PluginFormcreatorCommon::getDuplicateOf(Session::getActiveEntity(), GLPI_TMP_DIR . '/' . $filename)) {
499-
$this->value = str_replace('id="' . $input['_tag_description'] . '"', $document->fields['tag'], $this->value);
500-
$input['_tag_description'][$id] = $document->fields['tag'];
501-
}
502-
}
503-
504-
foreach ($input['_tag_description'] as $tag) {
505-
$regex = '/<img[^>]+' . preg_quote($tag, '/') . '[^<]+>/im';
506-
$input['description'] = preg_replace($regex, "#$tag#", $input['description']);
507-
}
508-
}
509-
510466
// generate a unique id
511467
if (!isset($input['uuid'])
512468
|| empty($input['uuid'])) {
@@ -651,13 +607,53 @@ public function pre_deleteItem() {
651607
}
652608

653609
public function post_addItem() {
610+
$this->input = $this->addFiles(
611+
$this->input,
612+
[
613+
'force_update' => true,
614+
'content_field' => 'description',
615+
'name' => 'description',
616+
]
617+
);
618+
619+
if ($this->input['fieldtype'] == 'textarea') {
620+
$this->input = $this->addFiles(
621+
$this->input,
622+
[
623+
'force_update' => true,
624+
'content_field' => 'default_values',
625+
'name' => 'default_values',
626+
]
627+
);
628+
}
629+
654630
$this->updateConditions($this->input);
655631
if (!$this->skipChecks) {
656632
$this->updateParameters($this->input);
657633
}
658634
}
659635

660636
public function post_updateItem($history = 1) {
637+
$this->input = $this->addFiles(
638+
$this->input,
639+
[
640+
'force_update' => true,
641+
'content_field' => 'description',
642+
'name' => 'description',
643+
]
644+
);
645+
646+
if (($this->input['fieldtype'] ?? $this->fields['fieldtype']) == 'textarea') {
647+
$this->input = $this->addFiles(
648+
$this->input,
649+
[
650+
'force_update' => true,
651+
'content_field' => 'default_values',
652+
'name' => 'default_values',
653+
]
654+
);
655+
}
656+
661657
$this->updateConditions($this->input);
662658
if (!$this->skipChecks) {
663659
$this->updateParameters($this->input);
@@ -1369,5 +1365,4 @@ public static function dropdownObjectSubType(string $name, array $options = []):
13691365
],
13701366
] + $options);
13711367
}
1372-
13731368
}

0 commit comments

Comments
 (0)