Commit b9dab562 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Refs #10013 First implementation of CodeMirror.

parent 671269ad
Pipeline #3199 passed with stages
in 3 minutes and 40 seconds
......@@ -3173,6 +3173,37 @@ abstract class AbstractBuildForm {
return $element . HelperFormElement::getHelpBlock();
}
/**
* @param array $formElement
* @param $htmlFormElementName
* @param $value
* @param array $json
* @param string $mode
* @return string
* @throws \CodeException
* @throws \UserFormException
* @throws \UserReportException
*/
public function buildEditor(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) {
if (empty($formElement[FE_EDITOR_TYPE])) {
$formElement[FE_EDITOR_TYPE] = FE_EDITOR_TYPE_TINYMCE;
}
switch ($formElement[FE_EDITOR_TYPE]) {
case FE_EDITOR_TYPE_TINYMCE:
$html = $this->buildEditorTinyMCE($formElement, $htmlFormElementName, $value, $json, $mode);
break;
case FE_EDITOR_TYPE_CODEMIRROR:
$html = $this->buildEditorCodeMirror($formElement, $htmlFormElementName, $value, $json, $mode);
break;
default:
throw new \UserFormException("Unexpected editor type: '" . $formElement[FE_EDITOR_TYPE] . "'", ERROR_FORMELEMENT_EDITOR_TYPE);
}
return $html;
}
/**
* Build a HTML 'textarea' element which becomes a TinyMCE Editor.
* List of possible plugins: https://www.tinymce.com/docs/plugins/
......@@ -3188,11 +3219,9 @@ abstract class AbstractBuildForm {
* @throws \UserFormException
* @throws \UserReportException
*/
public function buildEditor(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) {
public function buildEditorTinyMCE(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) {
$attribute = '';
//TODO plugin autoresize nutzen um Editorgroesse anzugeben
$attribute .= Support::doAttribute('id', $formElement[FE_HTML_ID]);
$attribute .= Support::doAttribute('name', $htmlFormElementName);
// $attribute .= Support::doAttribute('id', $htmlFormElementName);
......@@ -3205,7 +3234,7 @@ abstract class AbstractBuildForm {
$attribute .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attribute .= Support::doAttribute('data-title', $formElement[FE_TOOLTIP]);
$formElement = $this->setEditorConfig($formElement, $htmlFormElementName);
$formElement = $this->setEditorTinyMCEConfig($formElement, $htmlFormElementName);
// $formElement['editor-plugins']='autoresize code'
// $formElement['editor-contextmenu']='link image | cell row column'
$json = $this->getPrefixedElementsAsJSON(FE_EDITOR_PREFIX, $formElement);
......@@ -3223,6 +3252,55 @@ abstract class AbstractBuildForm {
return $html . HelperFormElement::getHelpBlock() . $formElement[FE_TMP_EXTRA_BUTTON_HTML] . $formElement[FE_INPUT_EXTRA_BUTTON_INFO];
}
/**
* @param array $formElement
* @param $htmlFormElementName
* @param $value
* @param array $json
* @param $mode
* @return string
* @throws \CodeException
* @throws \UserFormException
* @throws \UserReportException
*/
public function buildEditorCodeMirror(array $formElement, $htmlFormElementName, $value, array &$json, $mode) {
$attribute = '';
$attribute .= Support::doAttribute('id', $formElement[FE_HTML_ID]);
$attribute .= Support::doAttribute('name', $htmlFormElementName);
// $attribute .= Support::doAttribute('id', $htmlFormElementName);
$attribute .= Support::doAttribute(ATTRIBUTE_DATA_REFERENCE, $formElement[FE_DATA_REFERENCE]);
$attribute .= Support::doAttribute('class', 'qfq-codemirror');
// $attribute .= Support::doAttribute('data-control-name', "$htmlFormElementName");
// $attribute .= Support::doAttribute('data-placeholder', $formElement[FE_PLACEHOLDER]);
// $attribute .= Support::doAttribute('data-autofocus', $formElement[FE_AUTOFOCUS]);
// $attribute .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
// $attribute .= Support::doAttribute('data-title', $formElement[FE_TOOLTIP]);
// $formElement = $this->setEditorTinyMCEConfig($formElement, $htmlFormElementName);
// $formElement['editor-plugins']='autoresize code'
// $formElement['editor-contextmenu']='link image | cell row column'
$formElement[FE_EDITOR_PREFIX . 'mode'] = $formElement[FE_EDITOR_PREFIX . 'mode'] ?? "text/x-sql";
$formElement[FE_EDITOR_PREFIX . 'lineNumbers'] = $formElement[FE_EDITOR_PREFIX . 'lineNumbers'] ?? true;
$json = $this->getPrefixedElementsAsJSON(FE_EDITOR_PREFIX, $formElement);
$attribute .= Support::doAttribute('data-config', $json, true);
$attribute .= HelperFormElement::getAttributeFeMode($formElement[FE_MODE]);
$attribute .= HelperFormElement::getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$json = $this->getFormElementForJson($htmlFormElementName, $value, $formElement);
$html = Support::wrapTag("<textarea $attribute>", htmlentities($value), false);
$formElement = HelperFormElement::prepareExtraButton($formElement, false);
return $html . HelperFormElement::getHelpBlock() . $formElement[FE_TMP_EXTRA_BUTTON_HTML] . $formElement[FE_INPUT_EXTRA_BUTTON_INFO];
}
/**
* Parse $formElement[FE_EDITOR_*] settings and build editor settings.
*
......@@ -3231,7 +3309,7 @@ abstract class AbstractBuildForm {
*
* @return array
*/
private function setEditorConfig(array $formElement, $htmlFormElementName) {
private function setEditorTinyMCEConfig(array $formElement, $htmlFormElementName) {
$flagMaxHeight = false;
// plugins
......@@ -3274,6 +3352,7 @@ abstract class AbstractBuildForm {
return $formElement;
}
/**
* Searches for '$prefix*' elements in $formElement. Collect all found elements, strip $prefix (=$keyName) and
* returns keys/values JSON encoded.
......
......@@ -165,7 +165,7 @@ const ERROR_USER_NOT_LOGGED_IN = 1017;
const ERROR_USER_LOGGED_IN = 1018;
const ERROR_FORM_FORBIDDEN = 1019;
const ERROR_FORM_UNKNOWN_PERMISSION_MODE = 1020;
const ERROR_FORMELEMENT_EDITOR_TYPE = 1021;
const ERROR_TOKEN_MISSING = 1022;
const ERROR_RECURSION_TOO_DEEP = 1023;
const ERROR_CHECKBOXMODE_UNKNOWN = 1024;
......@@ -1185,6 +1185,9 @@ const FE_SQL_INSERT = 'sqlInsert'; // Action: Insert Statement to create slave r
const FE_SQL_DELETE = 'sqlDelete'; // Action: Delete Statement to delete unused slave record.
const FE_SQL_HONOR_FORM_ELEMENTS = 'sqlHonorFormElements'; // Action: Honor given list of FormElements for sqlInsert|Update|Delete
const FE_EDITOR_PREFIX = 'editor-'; // TinyMCE configuration settings.
const FE_EDITOR_TYPE = 'editorType'; // tinymce | codemirror
const FE_EDITOR_TYPE_TINYMCE = 'tinymce';
const FE_EDITOR_TYPE_CODEMIRROR = 'codemirror';
const FE_SENDMAIL_TO = 'sendMailTo'; // Receiver email adresses. Separate multiple by comma.
const FE_SENDMAIL_CC = 'sendMailCc'; // CC Receiver email adresses. Separate multiple by comma.
const FE_SENDMAIL_BCC = 'sendMailBcc'; // BCC Receiver email adresses. Separate multiple by comma.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment