Commit 0bb99fd1 authored by Elias Villiger's avatar Elias Villiger
Browse files

B3613 - Refactor BuildFormBootstrap::customWrap - refs #3613

parent 8203e8f7
......@@ -720,41 +720,37 @@ EOF;
$htmlLabel = $this->buildLabel($htmlFormElementName, $formElement[FE_LABEL], $addClass);
}
$html .= $this->customWrap($formElement, $htmlLabel, FE_WRAP_LABEL, $formElement[FE_BS_LABEL_COLUMNS],
[$this->wrap[WRAP_SETUP_LABEL][WRAP_SETUP_START], $this->wrap[WRAP_SETUP_LABEL][WRAP_SETUP_END]], $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_LABEL);
$html .= $this->customWrap($formElement, $htmlLabel, WRAP_SETUP_LABEL, FE_WRAP_LABEL, $formElement[FE_BS_LABEL_COLUMNS],
$formElement[FE_HTML_ID] . HTML_ID_EXTENSION_LABEL);
// Input
$html .= $this->customWrap($formElement, $htmlElement, FE_WRAP_INPUT, $formElement[FE_BS_INPUT_COLUMNS],
[$this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_START], $this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_END]],
$html .= $this->customWrap($formElement, $htmlElement, WRAP_SETUP_INPUT, FE_WRAP_INPUT, $formElement[FE_BS_INPUT_COLUMNS],
$formElement[FE_HTML_ID] . HTML_ID_EXTENSION_INPUT, $classHideElement);
// Note
$note = $formElement[FE_NOTE];
$html .= $this->customWrap($formElement, $note, FE_WRAP_NOTE, $formElement[FE_BS_NOTE_COLUMNS],
[$this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_START], $this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_END]], $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_NOTE);
$html .= $this->customWrap($formElement, $note, WRAP_SETUP_NOTE, FE_WRAP_NOTE, $formElement[FE_BS_NOTE_COLUMNS],
$formElement[FE_HTML_ID] . HTML_ID_EXTENSION_NOTE);
// Row
$openTag = $formElement[FE_FLAG_ROW_OPEN_TAG] ? $this->getRowOpenTag($classHideRow) : '';
$closeTag = $formElement[FE_FLAG_ROW_CLOSE_TAG] ? $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_END] : '';
$html = $this->customWrap($formElement, $html, FE_WRAP_ROW, -1, [$openTag, $closeTag], $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_ROW);
$html = $this->customWrap($formElement, $html, WRAP_SETUP_ELEMENT, FE_WRAP_ROW -1, $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_ROW, $classHideRow);
return $html;
}
/**
* Wrap content with $wrapArray or, if specified use $formElement[$wrapName]. Inject $htmlId in wrap.
* Wrap content as defined in this->wrap or, if specified use $formElement[$wrapName]. Inject $htmlId in wrap.
*
* Result:
* - if $bsColumns==0 and empty $formElement[$wrapName]: no wrap
* - if $formElement[$wrapName] is given: wrap with that one. Else: wrap with $wrapArray
* - if $htmlId is give, inject it in $wrap.
* - if $formElement[$customWrapName] is given: wrap with that one.
* - if $htmlId is given, inject it in $wrap.
*
* @param array $formElement Complete FormElement, especially some FE_WRAP
* @param string $htmlElement Content to wrap.
* @param string $wrapType WRAP_SETUP_ELEMENT, WRAP_SETUP_LABEL, WRAP_SETUP_INPUT, WRAP_SETUP_NOTE
* @param string $wrapName FE_WRAP_ROW, FE_WRAP_LABEL, FE_WRAP_INPUT, FE_WRAP_NOTE
* @param int $bsColumns
* @param array $wrapArray Systemwide Defaults: [ 'open wrap', 'close wrap' ]
* @param string $htmlId
* @param string $class
*
......@@ -762,29 +758,42 @@ EOF;
* @throws CodeException
* @throws \qfq\UserFormException
*/
private function customWrap(array $formElement, $htmlElement, $wrapName, $bsColumns, array $wrapArray, $htmlId = '', $class = '') {
private function customWrap(array $formElement, $htmlElement, $wrapType, $wrapName, $bsColumns, $htmlId = '', $class = '') {
$openTag = '';
$closeTag = '';
// If $bsColumns==0: do not wrap with default.
if ($bsColumns == 0) {
$wrapArray[0] = '';
$wrapArray[1] = '';
if ($bsColumns != 0) {
switch ($wrapType) {
case WRAP_SETUP_ELEMENT;
$openTag = $formElement[FE_FLAG_ROW_OPEN_TAG] ? $this->getRowOpenTag($class) : '';
$closeTag = $formElement[FE_FLAG_ROW_CLOSE_TAG] ? $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_END] : '';
break;
case WRAP_SETUP_LABEL:
case WRAP_SETUP_INPUT:
case WRAP_SETUP_NOTE:
$openTag = $this->wrap[$wrapType][WRAP_SETUP_START];
$closeTag = $this->wrap[$wrapType][WRAP_SETUP_END];
break;
default:
throw new UserFormException("Unknown wrap for FormElement.parameter '$wrapType'.", ERROR_MISSING_VALUE);
break;
}
}
// If there is a 'per FormElement'-wrap, take it.
if (isset($formElement[$wrapName])) {
$wrapArray = explode('|', $formElement[$wrapName], 2);
$openTag = $wrapArray[0] ?? '';
$closeTag = $wrapArray[1] ?? '';
}
if (count($wrapArray) != 2) {
throw new UserFormException("Need open & close wrap token for FormElement.parameter" . $wrapName . " - E.g.: <div ...>|</div>", ERROR_MISSING_VALUE);
}
if ($wrapArray[0] != '') {
$wrapArray[0] = Support::insertAttribute($wrapArray[0], 'id', $htmlId);
$wrapArray[0] = Support::insertAttribute($wrapArray[0], 'class', $class); // might be problematic, if there is already a 'class' defined.
if ($openTag != '') {
$openTag = Support::insertAttribute($openTag, 'id', $htmlId);
$openTag = Support::insertAttribute($openTag, 'class', $class); // might be problematic, if there is already a 'class' defined.
}
return $wrapArray[0] . $htmlElement . $wrapArray[1];
return $openTag . $htmlElement . $closeTag;
}
......
......@@ -824,8 +824,8 @@ class Support {
// Will be used to change dynamicUpdate behaviour
if (isset($formElement[FE_WRAP_ROW_LABEL_INPUT_NOTE])) {
$formElement[FE_FLAG_ROW_OPEN_TAG] = Support::findInSet('row', $formElement[FE_WRAP_ROW_LABEL_INPUT_NOTE]);
$formElement[FE_FLAG_ROW_CLOSE_TAG] = Support::findInSet('/row', $formElement[FE_WRAP_ROW_LABEL_INPUT_NOTE]);
$formElement[FE_FLAG_ROW_OPEN_TAG] = self::findInSet('row', $formElement[FE_WRAP_ROW_LABEL_INPUT_NOTE]);
$formElement[FE_FLAG_ROW_CLOSE_TAG] = self::findInSet('/row', $formElement[FE_WRAP_ROW_LABEL_INPUT_NOTE]);
} else {
$formElement[FE_FLAG_ROW_OPEN_TAG] = true;
$formElement[FE_FLAG_ROW_CLOSE_TAG] = false;
......
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