Internal: Disable full-page mode in BaseTinyEditor for intro forms - refs BT#21569

pull/5425/head
christianbeeznst 1 year ago
parent 3f3b7f21ef
commit 6d82a9e7df
  1. 1
      assets/vue/components/ctoolintro/Form.vue
  2. 30
      src/CoreBundle/Controller/CourseController.php

@ -3,6 +3,7 @@
<BaseTinyEditor
v-model="item.introText"
editor-id="introText"
:full-page="false"
required
/>
<!-- For extra content-->

@ -579,12 +579,9 @@ class CourseController extends ToolBaseController
/** @var CToolIntro $ctoolintro */
$ctoolintro = $ctoolintroRepo->findOneBy(['courseTool' => $ctool]);
if ($ctoolintro) {
$introText = $ctoolintro->getIntroText();
$cleanedHtml = $this->processHtmlContent($introText);
$responseData = [
'iid' => $ctoolintro->getIid(),
'introText' => $cleanedHtml,
'introText' => $ctoolintro->getIntroText(),
'createInSession' => $createInSession,
'cToolId' => $ctool->getIid(),
];
@ -975,29 +972,4 @@ class CourseController extends ToolBaseController
return $enrollmentCount > 0;
}
private function processHtmlContent($htmlText): array|string|null
{
$doc = new \DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML(mb_convert_encoding($htmlText, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
libxml_clear_errors();
// Extract everything inside the <html> element, if present, or fallback to the document itself
$htmlContent = '';
$html = $doc->getElementsByTagName('html')->item(0);
if ($html) {
foreach ($html->childNodes as $child) {
$htmlContent .= $doc->saveHTML($child);
}
} else {
$htmlContent = $doc->saveHTML($doc->documentElement);
}
// Remove <html>, <head>, and <body> tags manually
$htmlContent = preg_replace('/<\/?(html|head|body)[^>]*>/i', '', $htmlContent);
return $htmlContent;
}
}

Loading…
Cancel
Save