mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01:00
N°5298 - Upgrade CKEditor to version 5
- correct textarea encoding for ckeditor https://ckeditor.com/docs/ckeditor5/latest/installation/getting-started/getting-and-setting-data.html#automatic-integration-with-html-forms
This commit is contained in:
@@ -2303,7 +2303,7 @@ JS
|
||||
$sHidden = "<input type=\"hidden\" id=\"{$iId}_count\" value=\"$iEntriesCount\"/>"; // To know how many entries the case log already contains
|
||||
|
||||
$sHTMLValue = "$sHeader<div class=\"ibo-caselog-entry-form--text-input\" $sStyle data-role=\"ibo-caselog-entry-form--text-input\">";
|
||||
$sHTMLValue .= "<textarea class=\"htmlEditor ibo-input-richtext-placeholder\" style=\"border:0;width:100%\" title=\"$sHelpText\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" rows=\"8\" cols=\"40\" id=\"$iId\">".utils::EscapeHtml($sEditValue)."</textarea>";
|
||||
$sHTMLValue .= "<textarea class=\"htmlEditor ibo-input-richtext-placeholder\" style=\"border:0;width:100%\" title=\"$sHelpText\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" rows=\"8\" cols=\"40\" id=\"$iId\">".CKEditorHelper::PrepareCKEditorValueTextEncodingForTextarea($sEditValue)."</textarea>";
|
||||
$sHTMLValue .= "$sPreviousLog</div>{$sValidationSpan}{$sReloadSpan}$sHidden";
|
||||
|
||||
// Note: This should be refactored for all types of attribute (see at the end of this function) but as we are doing this for a maintenance release, we are scheduling it for the next main release in to order to avoid regressions as much as possible.
|
||||
|
||||
@@ -57,11 +57,13 @@ class UIHTMLEditorWidget
|
||||
|
||||
/**
|
||||
* Get the HTML fragment corresponding to the HTML editor widget
|
||||
* @param WebPage $oP The web page used for all the output
|
||||
* @param Hash $aArgs Extra context arguments
|
||||
*
|
||||
* @param WebPage $oPage The web page used for all the output
|
||||
* @param array $aArgs Extra context arguments
|
||||
*
|
||||
* @return string The HTML fragment to be inserted into the page
|
||||
*/
|
||||
public function Display(WebPage $oPage, $aArgs = array())
|
||||
public function Display(WebPage $oPage, array $aArgs = array()) : string
|
||||
{
|
||||
$iId = $this->m_iId;
|
||||
$sCode = $this->m_sAttCode.$this->m_sNameSuffix;
|
||||
@@ -69,7 +71,8 @@ class UIHTMLEditorWidget
|
||||
$sHelpText = $this->m_sHelpText;
|
||||
$sValidationField = $this->m_sValidationField;
|
||||
|
||||
$sHtmlValue = "<div class=\"field_input_zone field_input_html ibo-input-wrapper\"><textarea class=\"htmlEditor ibo-input-richtext-placeholder\" title=\"$sHelpText\" name=\"attr_{$this->m_sFieldPrefix}{$sCode}\" id=\"$iId\">$sValue</textarea></div>$sValidationField";
|
||||
$sEncodedValue = CKEditorHelper::PrepareCKEditorValueTextEncodingForTextarea($sValue);
|
||||
$sHtmlValue = "<div class=\"field_input_zone field_input_html ibo-input-wrapper\"><textarea class=\"htmlEditor ibo-input-richtext-placeholder\" title=\"$sHelpText\" name=\"attr_{$this->m_sFieldPrefix}{$sCode}\" id=\"$iId\">$sEncodedValue</textarea></div>$sValidationField";
|
||||
|
||||
// Enable CKEditor
|
||||
CKEditorHelper::ConfigureCKEditorElementForWebPage($oPage, $iId, $sValue, true);
|
||||
|
||||
@@ -115,6 +115,19 @@ class CKEditorHelper
|
||||
return $aMentionConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode value when using CKEditor with a TextArea.
|
||||
* @see https://ckeditor.com/docs/ckeditor5/latest/installation/getting-started/getting-and-setting-data.html#automatic-integration-with-html-forms
|
||||
*
|
||||
* @param string $sValue
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function PrepareCKEditorValueTextEncodingForTextarea(string $sValue) : string
|
||||
{
|
||||
return str_replace( '&', '&', $sValue );
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CKEditor element (WebPage).
|
||||
*
|
||||
|
||||
@@ -161,7 +161,7 @@ EOF
|
||||
// First the edition area
|
||||
$oOutput->AddHtml('<div>');
|
||||
$sEditorClasses = $bRichEditor ? 'htmlEditor' : '';
|
||||
$oOutput->AddHtml('<textarea id="'.$this->oField->GetGlobalId().'" name="'.$this->oField->GetId().'" class="' . $sEditorClasses . ' form-control" rows="8" '.$sInputTags.'>'.$this->oField->GetCurrentValue().'</textarea>');
|
||||
$oOutput->AddHtml('<textarea id="'.$this->oField->GetGlobalId().'" name="'.$this->oField->GetId().'" class="' . $sEditorClasses . ' form-control" rows="8" '.$sInputTags.'>'. CKEditorHelper::PrepareCKEditorValueTextEncodingForTextarea($this->oField->GetCurrentValue()) .'</textarea>');
|
||||
$oOutput->AddHtml('</div>');
|
||||
// Then the previous entries if necessary
|
||||
if ($sFieldClass === 'Combodo\\iTop\\Form\\Field\\CaseLogField') {
|
||||
|
||||
@@ -156,7 +156,7 @@ class ConsoleSimpleFieldRenderer extends FieldRenderer
|
||||
}
|
||||
else
|
||||
{
|
||||
$oText = new TextArea("",$this->oField->GetCurrentValue(),$this->oField->GetGlobalId(),40,8);
|
||||
$oText = new TextArea("", CKEditorHelper::PrepareCKEditorValueTextEncodingForTextarea($this->oField->GetCurrentValue()),$this->oField->GetGlobalId(),40,8);
|
||||
$oText->AddCSSClasses(['ibo-input-field-wrapper', 'ibo-input']);
|
||||
$oValue->AddSubBlock($oText);
|
||||
// Some additional stuff if we are displaying it with a rich editor
|
||||
|
||||
Reference in New Issue
Block a user