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

Refactor: own class Checkobox

parent 913b7f3a
Pipeline #2869 failed with stages
in 1 minute and 51 seconds
......@@ -21,6 +21,7 @@ use IMATHUZH\Qfq\Core\Report\Link;
use IMATHUZH\Qfq\Core\Report\Report;
use IMATHUZH\Qfq\Core\Store\Sip;
use IMATHUZH\Qfq\Core\Store\Store;
use IMATHUZH\Qfq\Core\Form\Checkbox;
/**
* Class AbstractBuildForm
......@@ -1253,44 +1254,11 @@ abstract class AbstractBuildForm {
*/
private function getJsonFeMode($feMode) {
$this->getFeMode($feMode, $dummy, $disabled, $required);
HelperFormElement::getFeMode($feMode, $dummy, $disabled, $required);
return [API_FORM_UPDATE_DISABLED => ($disabled === 'yes'), API_FORM_UPDATE_REQUIRED => ($required === 'yes')];
}
/**
* Depending of $feMode set variables $hidden, $disabled, $required to 'yes' or 'no'.
*
* @param string $feMode
* @param string $hidden
* @param string $disabled
* @param string $required
*
* @throws \UserFormException
*/
private function getFeMode($feMode, &$hidden, &$disabled, &$required) {
$hidden = 'no';
$disabled = 'no';
$required = 'no';
switch ($feMode) {
case FE_MODE_SHOW:
case FE_MODE_SHOW_REQUIRED:
break;
case FE_MODE_REQUIRED:
$required = 'yes';
break;
case FE_MODE_READONLY:
$disabled = 'yes'; // convert the UI status 'readonly' to the HTML/CSS status 'disabled'.
break;
case FE_MODE_HIDDEN:
$hidden = 'yes';
break;
default:
throw new \UserFormException("Unknown mode '$feMode'", ERROR_UNKNOWN_MODE);
break;
}
}
/**
* Builds a label, typically for an html-'<input>'-element.
......@@ -1499,11 +1467,11 @@ abstract class AbstractBuildForm {
if (!empty($formElement[FE_INPUT_TYPE])) {
$formElement[FE_TYPE] = $formElement[FE_INPUT_TYPE];
}
$attribute .= $this->getAttributeList($formElement, [FE_TYPE, 'size']);
$attribute .= HelperFormElement::getAttributeList($formElement, [FE_TYPE, 'size']);
$attribute .= Support::doAttribute('value', htmlentities($value), false);
}
$attribute .= $this->getAttributeList($formElement, [FE_INPUT_AUTOCOMPLETE, 'autofocus', 'placeholder']);
$attribute .= HelperFormElement::getAttributeList($formElement, [FE_INPUT_AUTOCOMPLETE, 'autofocus', 'placeholder']);
$formElement[FE_CHECK_PATTERN] = Sanitize::getInputCheckPattern($formElement[FE_CHECK_TYPE], $formElement[FE_CHECK_PATTERN]
, $formElement[FE_DECIMAL_FORMAT], $sanitizeMessage);
......@@ -1526,12 +1494,12 @@ abstract class AbstractBuildForm {
$formElement[F_FE_DATA_REQUIRED_ERROR] = F_FE_DATA_REQUIRED_ERROR_DEFAULT;
}
$attribute .= $this->getAttributeList($formElement, [F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR, FE_MIN, FE_MAX, FE_STEP]);
$attribute .= HelperFormElement::getAttributeList($formElement, [F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR, FE_MIN, FE_MAX, FE_STEP]);
$attribute .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attribute .= Support::doAttribute('title', $formElement[FE_TOOLTIP]);
$attribute .= $this->getAttributeFeMode($formElement[FE_MODE], false);
$attribute .= HelperFormElement::getAttributeFeMode($formElement[FE_MODE], false);
$attribute .= Support::doAttribute('class', $class);
......@@ -1663,67 +1631,6 @@ abstract class AbstractBuildForm {
return $sql;
}
/**
* Builds a HTML attribute list, based on $attributeList.
*
* E.g.: attributeList: [ 'type', 'autofocus' ]
* generates: 'type="$formElement[FE_TYPE]" autofocus="$formElement[FE_AUTOFOCUS]" '
*
* @param array $formElement
* @param array $attributeList
* @param bool $flagOmitEmpty
*
* @return string
* @throws \CodeException
*/
private function getAttributeList(array $formElement, array $attributeList, $flagOmitEmpty = true) {
$attribute = '';
foreach ($attributeList as $item) {
if (isset($formElement[$item]))
$attribute .= Support::doAttribute(strtolower($item), $formElement[$item], $flagOmitEmpty);
}
return $attribute;
}
/**
* Set corresponding html attributes readonly/required/disabled, based on $formElement[FE_MODE].
*
* @param string $feMode
*
* @param bool $cssDisable
* @return string
* @throws \CodeException
* @throws \UserFormException
*/
private function getAttributeFeMode($feMode, $cssDisable = true) {
$attribute = '';
$this->getFeMode($feMode, $hidden, $disabled, $required);
switch ($feMode) {
case FE_MODE_HIDDEN:
case FE_MODE_SHOW:
case FE_MODE_SHOW_REQUIRED:
break;
case FE_MODE_REQUIRED:
case FE_MODE_READONLY:
$attribute .= Support::doAttribute($feMode, $feMode);
break;
default:
throw new \UserFormException("Unknown mode '$feMode'", ERROR_UNKNOWN_MODE);
break;
}
// Attributes: data-...
$attribute .= Support::doAttribute(DATA_HIDDEN, $hidden);
if ($cssDisable) {
$attribute .= Support::doAttribute(DATA_DISABLED, $disabled);
}
$attribute .= Support::doAttribute(DATA_REQUIRED, $required);
return $attribute;
}
/**
* Build HelpBlock
......@@ -1756,168 +1663,12 @@ abstract class AbstractBuildForm {
* @throws \UserReportException
*/
public function buildCheckbox(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) {
$itemKey = array();
$itemValue = array();
// Fill $itemKey & $itemValue
$this->getKeyValueListFromSqlEnumSpec($formElement, $itemKey, $itemValue);
// Get fallback, if 'checkBoxMode' is not defined:
if (!isset($formElement['checkBoxMode'])) {
// This fallback is problematic if 'set' or 'enum' has 2 : defaults to single but maybe multi is meant.
$formElement['checkBoxMode'] = (count($itemKey) > 2) ? 'multi' : 'single';
}
if ($formElement['checkBoxMode'] === 'multi') {
} else {
// Fill meaningful defaults to parameter: checked|unchecked (CHECKBOX_VALUE_CHECKED|CHECKBOX_VALUE_UNCHECKED)
$this->prepareCheckboxCheckedUncheckedValue($itemKey, $formElement);
}
$attributeBase = $this->getAttributeFeMode($formElement[FE_MODE]);
$attributeBase .= Support::doAttribute('type', $formElement[FE_TYPE]);
$attributeBase .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
switch ($formElement['checkBoxMode']) {
case 'single':
$html = $this->buildCheckboxSingle($formElement, $htmlFormElementName, $attributeBase, $value, $json);
break;
case 'multi';
$html = $this->buildCheckboxMulti($formElement, $htmlFormElementName, $attributeBase, $value, $itemKey, $itemValue, $json);
break;
default:
throw new \UserFormException('checkBoxMode: \'' . $formElement['checkBoxMode'] . '\' is unknown.', ERROR_CHECKBOXMODE_UNKNOWN);
}
$formElement = HelperFormElement::prepareExtraButton($formElement, false);
return $html . $formElement[FE_TMP_EXTRA_BUTTON_HTML] . $this->getHelpBlock() . $formElement[FE_INPUT_EXTRA_BUTTON_INFO];
}
/**
* Look for key/value list (in this order, first match counts) in
* a) `sql1`
* b) `parameter:itemList`
* c) table.column definition
*
* Copies the found keys to &$itemKey and the values to &$itemValue
* If there are no &$itemKey, copy &$itemValue to &$itemKey.
*
* @param array $formElement
* @param array $itemKey
* @param array $itemValue
*
* @throws \CodeException
* @throws \UserFormException
*/
public function getKeyValueListFromSqlEnumSpec(array $formElement, array &$itemKey, array &$itemValue) {
$fieldType = '';
$itemKey = array();
$itemValue = array();
// Call getItemsForEnumOrSet() only if there a corresponding column really exist.
if (false !== $this->store->getVar($formElement[FE_NAME], STORE_TABLE_COLUMN_TYPES)) {
$itemValue = $this->getItemsForEnumOrSet($formElement[FE_NAME], $fieldType);
}
if (is_array($formElement[FE_SQL1])) {
if (count($formElement[FE_SQL1]) > 0) {
$keys = array_keys($formElement[FE_SQL1][0]);
$itemKey = array_column($formElement[FE_SQL1], 'id');
// If there is no column 'id' and at least two columns in total
if (count($itemKey) === 0 && count($keys) >= 2) {
$itemKey = array_column($formElement[FE_SQL1], $keys[0]);
}
$itemValue = array_column($formElement[FE_SQL1], 'label');
// If there is no column 'label' (e.g.: SHOW tables)
if (count($itemValue) === 0) {
$idx = count($keys) == 1 ? 0 : 1;
$itemValue = array_column($formElement[FE_SQL1], $keys[$idx]);
}
}
} elseif (isset($formElement['itemList']) && strlen($formElement['itemList']) > 0) {
$arr = KeyValueStringParser::parse($formElement['itemList'], ':', ',', KVP_IF_VALUE_EMPTY_COPY_KEY);
$itemValue = array_values($arr);
$itemKey = array_keys($arr);
} elseif ($fieldType === 'enum' || $fieldType === 'set') {
// already done at the beginning with '$this->getItemsForEnumOrSet($formElement[FE_NAME], $fieldType);'
} elseif (isset($formElement[FE_CHECKBOX_CHECKED]) && $formElement[FE_TYPE] == FE_TYPE_CHECKBOX) {
// Nothing to do here.
} else {
throw new \UserFormException("Missing definition (- nothing found in 'sql1', 'parameter:itemList', 'enum-' or 'set-definition'", ERROR_MISSING_ITEM_LIST);
}
if (count($itemKey) === 0) {
$itemKey = $itemValue;
}
// Process 'emptyHide' before 'emptyItemAtStart' / 'emptyItemAtEnd': than 'emptyItem*' are still possible.
if (isset($formElement['emptyHide'])) {
$itemKey = OnArray::removeEmptyElementsFromArray($itemKey);
$itemValue = OnArray::removeEmptyElementsFromArray($itemValue);
}
if (isset($formElement[FE_EMPTY_ITEM_AT_START])) {
$placeholder = isset($formElement[FE_PLACEHOLDER]) ? $formElement[FE_PLACEHOLDER] : '';
array_unshift($itemKey, '');
array_unshift($itemValue, $placeholder);
}
if (isset($formElement[FE_EMPTY_ITEM_AT_END])) {
$itemKey[] = '';
$itemValue[] = '';
}
$checkbox = new Checkbox;
return $checkbox->build($formElement, $htmlFormElementName, $value, $json, $mode);
}
/**
* Get the attribute definition list of an enum or set column. For strings, get the default value. Return
* elements as an array.
*
* @param string $column
* @param string $fieldType
*
* @return array
* @throws \CodeException
* @throws \UserFormException
*/
private function getItemsForEnumOrSet($column, &$fieldType) {
// Get column definition
$fieldTypeDefinition = $this->store->getVar($column, STORE_TABLE_COLUMN_TYPES);
if ($fieldTypeDefinition === false) {
throw new \UserFormException("Column '$column' unknown in table '" . $this->formSpec[F_TABLE_NAME] . "'", ERROR_DB_UNKNOWN_COLUMN);
}
$length = strlen($fieldTypeDefinition);
// enum('... set('
switch (substr($fieldTypeDefinition, 0, 4)) {
case 'enum':
$startPosition = 5;
break;
case 'set(':
$startPosition = 4;
break;
default:
$fieldType = 'string';
return array();
}
// enum('a','b','c', ...) >> [ 'a', 'b', 'c', ... ]
// set('a','b','c', ...) >> [ 'a', 'b', 'c', ... ]
$values = substr($fieldTypeDefinition, $startPosition, $length - $startPosition - 1);
$items = OnArray::trimArray(explode(',', $values), "'");
$fieldType = substr($fieldTypeDefinition, 0, $startPosition - 1);
return $items;
}
/**
* For CheckBox's with only one checkbox: if no parameter:checked|unchecked is defined, take defaults:
*
......@@ -2028,8 +1779,8 @@ abstract class AbstractBuildForm {
$classActive = ' active';
}
$attribute .= $this->getAttributeList($formElement, ['autofocus']);
$attribute .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$attribute .= HelperFormElement::getAttributeList($formElement, ['autofocus']);
$attribute .= HelperFormElement::getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$htmlHidden = $this->buildNativeHidden($htmlFormElementName, $formElement[FE_CHECKBOX_UNCHECKED]);
$this->store->setVar($htmlFormElementName, $htmlHidden, STORE_ADDITIONAL_FORM_ELEMENTS, false);
......@@ -2086,8 +1837,8 @@ abstract class AbstractBuildForm {
$valueJson = $value;
}
$attribute .= $this->getAttributeList($formElement, ['autofocus']);
$attribute .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$attribute .= HelperFormElement::getAttributeList($formElement, ['autofocus']);
$attribute .= HelperFormElement::getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$htmlHidden = $this->buildNativeHidden($htmlFormElementName, $formElement[FE_CHECKBOX_UNCHECKED]);
$this->store->setVar($htmlFormElementName, $htmlHidden, STORE_ADDITIONAL_FORM_ELEMENTS, false);
......@@ -2190,7 +1941,7 @@ abstract class AbstractBuildForm {
$values = explode(',', $value);
$attributeBase .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attributeBase .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$attributeBase .= HelperFormElement::getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$key = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, 'h', true);
$htmlHidden = $this->buildNativeHidden($key, '');
......@@ -2265,7 +2016,7 @@ abstract class AbstractBuildForm {
$values = explode(',', $value);
$attributeBase .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attributeBase .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$attributeBase .= HelperFormElement::getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
// 'font-weight: 400;': class 'checkbox' forces bold for the label - this is not ok.
$attributeBaseLabel = Support::doAttribute('style', 'min-width: ' . $formElement[F_FE_MIN_WIDTH] . 'px; font-weight: 400;');
......@@ -2448,16 +2199,17 @@ abstract class AbstractBuildForm {
* @return string
* @throws \CodeException
* @throws \UserFormException
* @throws \UserReportException
*/
private function constructRadioButton(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) {
$itemKey = array();
$itemValue = array();
// Fill $itemKey & $itemValue
$this->getKeyValueListFromSqlEnumSpec($formElement, $itemKey, $itemValue);
HelperFormElement::getKeyValueListFromSqlEnumSpec($formElement, $itemKey, $itemValue);
$attributeBase = $this->getAttributeFeMode($formElement[FE_MODE]);
$attributeBase .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$attributeBase = HelperFormElement::getAttributeFeMode($formElement[FE_MODE]);
$attributeBase .= HelperFormElement::getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
// $attributeBase .= Support::doAttribute('id', $formElement[FE_HTML_ID]);
$attributeBase .= Support::doAttribute('name', $htmlFormElementName);
$attributeBase .= Support::doAttribute('type', $formElement[FE_TYPE]);
......@@ -2542,10 +2294,10 @@ abstract class AbstractBuildForm {
$itemValue = array();
// Fill $itemKey & $itemValue
$this->getKeyValueListFromSqlEnumSpec($formElement, $itemKey, $itemValue);
HelperFormElement::getKeyValueListFromSqlEnumSpec($formElement, $itemKey, $itemValue);
$attributeBase .= $this->getAttributeFeMode($formElement[FE_MODE]);
$attributeBase .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$attributeBase .= HelperFormElement::getAttributeFeMode($formElement[FE_MODE]);
$attributeBase .= HelperFormElement::getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$attributeBase .= Support::doAttribute('name', $htmlFormElementName);
$attributeBase .= Support::doAttribute('type', $formElement[FE_TYPE]);
$attributeBase .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
......@@ -2654,13 +2406,13 @@ abstract class AbstractBuildForm {
}
// Fill $itemKey & $itemValue
$this->getKeyValueListFromSqlEnumSpec($formElement, $itemKey, $itemValue);
HelperFormElement::getKeyValueListFromSqlEnumSpec($formElement, $itemKey, $itemValue);
$attribute .= Support::doAttribute('id', $formElement[FE_HTML_ID]);
$attribute .= Support::doAttribute('name', $htmlFormElementName);
$attribute .= Support::doAttribute('class', 'form-control');
$attribute .= Support::doAttribute('title', $formElement[FE_TOOLTIP]);
$attribute .= $this->getAttributeList($formElement, ['autofocus', F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR]);
$attribute .= HelperFormElement::getAttributeList($formElement, ['autofocus', F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR]);
$attribute .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attribute .= Support::doAttribute(ATTRIBUTE_DATA_REFERENCE, $formElement[FE_DATA_REFERENCE]);
......@@ -2699,7 +2451,7 @@ abstract class AbstractBuildForm {
$json = $this->getFormElementForJson($htmlFormElementName, $jsonValues, $formElement);
$formElement = HelperFormElement::prepareExtraButton($formElement, false);
$attribute .= $this->getAttributeFeMode($formElement[FE_MODE]);
$attribute .= HelperFormElement::getAttributeFeMode($formElement[FE_MODE]);
if (isset($formElement["datalist"])) {
if ($formElement[FE_DYNAMIC_UPDATE] === 'yes') {
throw new \UserFormException("Datalist funktionert nicht mit dynamic update", ERROR_NOT_IMPLEMENTED);
......@@ -3339,7 +3091,7 @@ abstract class AbstractBuildForm {
$attribute .= Support::doAttribute('type', 'file');
$attribute .= Support::doAttribute('title', $formElement[FE_TOOLTIP]);
$attribute .= Support::doAttribute(FE_FILE_CAPTURE, $formElement[FE_FILE_CAPTURE], true);
$attribute .= $this->getAttributeList($formElement, [FE_AUTOFOCUS, FE_FILE_MIME_TYPE_ACCEPT]);
$attribute .= HelperFormElement::getAttributeList($formElement, [FE_AUTOFOCUS, FE_FILE_MIME_TYPE_ACCEPT]);
$attribute .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attribute .= Support::doAttribute('data-sip', $sipUpload);
$attribute .= Support::doAttribute(ATTRIBUTE_DATA_REFERENCE, $formElement[FE_DATA_REFERENCE]);
......@@ -3361,7 +3113,7 @@ abstract class AbstractBuildForm {
// $formElement[FE_MODE] = FE_MODE_HIDDEN; // #3876, CR did not understand why we need this here. Comment. If active, this element will be hide on each dynamic update.
}
$attribute .= $this->getAttributeFeMode($formElement[FE_MODE]);
$attribute .= HelperFormElement::getAttributeFeMode($formElement[FE_MODE]);
$attribute .= Support::doAttribute('class', $uploadClass, true);
// $htmlInputFile = '<input ' . $attribute . '>' . $this->getHelpBlock();
......@@ -3485,7 +3237,7 @@ abstract class AbstractBuildForm {
$attributeDiv .= Support::doAttribute('data-file', $this->fileToSipUrl($formElement[FE_TEXT_SOURCE]));
$attributeDiv .= Support::doAttribute('data-target', $formElement[FE_HTML_ID]);
$attributeDiv .= Support::doAttribute('data-highlight', $dataHighlight);
$attributeDiv .= $this->getAttributeFeMode($formElement[FE_MODE]);
$attributeDiv .= HelperFormElement::getAttributeFeMode($formElement[FE_MODE]);
if ($formElement[FE_MODE] == FE_MODE_READONLY) {
$attributeDiv .= Support::doAttribute('data-view-only', 'true');
}
......@@ -3550,7 +3302,7 @@ abstract class AbstractBuildForm {
$attributeFabric .= Support::doAttribute('data-buttons', 'typo3conf/ext/qfq/Resources/Public/Json/fabric.buttons.json');
$attributeFabric .= Support::doAttribute('data-emojis', 'typo3conf/ext/qfq/Resources/Public/Json/qfq.emoji.json');
$attributeFabric .= Support::doAttribute('data-fabric-color', HelperFormElement::penColorToHex($formElement));
$attributeFabric .= $this->getAttributeFeMode($formElement[FE_MODE]);
$attributeFabric .= HelperFormElement::getAttributeFeMode($formElement[FE_MODE]);
if ($formElement[FE_MODE] == FE_MODE_READONLY) {
$attributeFabric .= Support::doAttribute('data-view-only', 'true');
}
......@@ -3621,7 +3373,7 @@ abstract class AbstractBuildForm {
$attributeFabric .= Support::doAttribute('data-image-resize-width', $formElement[FE_IMAGE_CUT_RESIZE_WIDTH]);
}
$attributeFabric .= Support::doAttribute('data-image-output', $htmlFabricImageId);
$attributeFabric .= $this->getAttributeFeMode($formElement[FE_MODE]);
$attributeFabric .= HelperFormElement::getAttributeFeMode($formElement[FE_MODE]);
$htmlFabric = Support::wrapTag('<div ' . $attributeFabric . ' >', '', false);
......@@ -3728,7 +3480,7 @@ abstract class AbstractBuildForm {
// 'maxLength' needs an upper 'L': naming convention for DB tables!
$attribute .= $this->getAttributeList($formElement, ['size', 'maxLength']);
$attribute .= HelperFormElement::getAttributeList($formElement, ['size', 'maxLength']);
$attribute .= Support::doAttribute('value', htmlentities($value), false);
if ($formElement[FE_PLACEHOLDER] == '') {
......@@ -3754,9 +3506,9 @@ abstract class AbstractBuildForm {
$formElement[F_FE_DATA_PATTERN_ERROR] = "Please match the format: " . $placeholder;
}
$attribute .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$attribute .= HelperFormElement::getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$attribute .= $this->getAttributeList($formElement, [FE_INPUT_AUTOCOMPLETE, 'autofocus', 'placeholder']);
$attribute .= HelperFormElement::getAttributeList($formElement, [FE_INPUT_AUTOCOMPLETE, 'autofocus', 'placeholder']);
$attribute .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attribute .= Support::doAttribute('title', $formElement[FE_TOOLTIP]);
......@@ -3768,13 +3520,13 @@ abstract class AbstractBuildForm {
$formElement[F_FE_DATA_PATTERN_ERROR] = $sanitizeMessage;
}
$attribute .= $this->getAttributeList($formElement, [FE_MIN, FE_MAX]);
$attribute .= HelperFormElement::getAttributeList($formElement, [FE_MIN, FE_MAX]);
$json = $this->getFormElementForJson($htmlFormElementName, $value, $formElement);
$formElement = HelperFormElement::prepareExtraButton($formElement, true);
$attribute .= $this->getAttributeFeMode($formElement[FE_MODE]);
$attribute .= HelperFormElement::getAttributeFeMode($formElement[FE_MODE]);
$input = "<input $attribute>" . $this->getHelpBlock() . $formElement[FE_TMP_EXTRA_BUTTON_HTML];
......@@ -3864,7 +3616,7 @@ abstract class AbstractBuildForm {
// $attribute .= Support::doAttribute('data-max', $arrMinMax[1]);
// }
$attribute .= $this->getAttributeFeMode($formElement[FE_MODE]);
$attribute .= HelperFormElement::getAttributeFeMode($formElement[FE_MODE]);
// $json = $this->getJsonElementUpdate($htmlFormElementName, $value, $formElement[FE_MODE]);
......@@ -3912,8 +3664,8 @@ abstract class AbstractBuildForm {
$attribute .= Support::doAttribute('data-config', $json, true);
$attribute .= $this->getAttributeFeMode($formElement[FE_MODE]);
$attribute .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$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);
......
......@@ -1328,7 +1328,7 @@ const FE_ORDER_INTERVAL_DEFAULT = '10';
const FE_ORDER_COLUMN = 'orderColumn';
const FE_DND_TABLE = 'dndTable';
CONST FE_TMP_CLASS_OPTION = '_classOption';
const FE_TMP_CLASS_OPTION = '_classOption';
const MODE_ENCODE = 'encode';
const MODE_DECODE = 'decode';
......
<?php
/**
* Created by PhpStorm.
* User: crose
* Date: 12/5/19
* Time: 11:09 AM
*/
namespace IMATHUZH\Qfq\Core\Form;
//use IMATHUZH\Qfq\Core\Database\Database;
//use IMATHUZH\Qfq\Core\Helper\HelperFile;
//use IMATHUZH\Qfq\Core\Helper\HelperFormElement;
//use IMATHUZH\Qfq\Core\Helper\KeyValueStringParser;
//use IMATHUZH\Qfq\Core\Helper\Ldap;
//use IMATHUZH\Qfq\Core\Helper\Logger;
//use IMATHUZH\Qfq\Core\Helper\OnArray;
//use IMATHUZH\Qfq\Core\Helper\Sanitize;
use IMATHUZH\Qfq\Core\Helper\Support;
//use IMATHUZH\Qfq\Core\Report\Link;
//use IMATHUZH\Qfq\Core\Report\Report;
//use IMATHUZH\Qfq\Core\Store\Sip;
use IMATHUZH\Qfq\Core\Helper\HelperFormElement;
use IMATHUZH\Qfq\Core\Store\Store;
/**
* Class Checkbox
* @package IMATHUZH\Qfq\Core\Form
*/
class Checkbox {
/**
* @var Store
*/
private $store = null;
/**
* Builds HTML 'checkbox' element.
*
* Checkboxes will only be submitted, if they are checked. Therefore, a hidden element with the unchecked value
* will be transferred first.
*
* Format: <input type="hidden" name="$htmlFormElementName" value="$valueUnChecked">
* <input name="$htmlFormElementName" type="checkbox" [autofocus="autofocus"]
* [required="required"] [disabled="disabled"] value="<value>" [checked="checked"] >
*
* @param array $formElement
* @param string $htmlFormElementName
* @param string $value
* @param array $json
* @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE*
*
* @return string
* @throws \CodeException
* @throws \UserFormException
* @throws \UserReportException
*/
public function build(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) {
$itemKey = array();