Commit 2b29d2ca authored by Carsten  Rose's avatar Carsten Rose
Browse files

Create function `Database->getNativeFormElements()` to unify all needed...

Create function `Database->getNativeFormElements()` to unify all needed actions on fresh loaded FormElements like explodeParameterInArrayElements, duplicateRetypEelements, copyAttributesToFormElements. Native FormElements will be loaded on 4 different places in 3 classes.

HelperFormElement.php: Moved copyAttributesToFormElements() from QuickFormQuery to HelperFormElement.
AbstractBuildForm.php, BuildFormBootstrap.php, QuickFormQuery.php : Use of Database->getNativeFormElements()
Database.php: HelperFormElement::copyAttributesToFormElements()
parent 8f86beee
......@@ -2297,11 +2297,10 @@ abstract class AbstractBuildForm {
$html .= $this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_START];
// child FE's
$sql = SQL_FORM_ELEMENT_SPECIFIC_CONTAINER;
$this->feSpecNative = $this->db->sql($sql, ROW_REGULAR, ['yes', $this->formSpec["id"], 'native,container', $formElement['id']]);
HelperFormElement::explodeParameterInArrayElements($this->feSpecNative);
$html .= $this->elements($this->store->getVar(SIP_RECORD_ID, STORE_SIP), FORM_ELEMENTS_NATIVE_SUBRECORD, 0, $json);
$this->feSpecNative = $this->db->getNativeFormElements(SQL_FORM_ELEMENT_SPECIFIC_CONTAINER,
['yes', $this->formSpec["id"], 'native,container', $formElement['id']], $this->formSpec);
$html .= $this->elements($this->store->getVar(SIP_RECORD_ID, STORE_SIP), FORM_ELEMENTS_NATIVE_SUBRECORD, 0, $json);
$html .= $this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_END];
......
......@@ -388,9 +388,9 @@ EOF;
$tmpStore = $this->feSpecNative;
// child FE's
$sql = SQL_FORM_ELEMENT_SPECIFIC_CONTAINER;
$this->feSpecNative = $this->db->sql($sql, ROW_REGULAR, ['yes', $this->formSpec["id"], 'native,container', $formElement['id']]);
HelperFormElement::explodeParameterInArrayElements($this->feSpecNative);
$this->feSpecNative = $this->db->getNativeFormElements(SQL_FORM_ELEMENT_SPECIFIC_CONTAINER,
['yes', $this->formSpec["id"], 'native,container', $formElement['id']], $this->formSpec);
$html = $this->elements($this->store->getVar(SIP_RECORD_ID, STORE_SIP), FORM_ELEMENTS_NATIVE_SUBRECORD, 0, $json);
// restore parent processed FE's
......
......@@ -617,4 +617,30 @@ class Database {
return $found;
}
/**
* Depending on $sql reads FormElements to a specific container or all. Preprocess all FormElements.
*
* @param string $sql SQL_FORM_ELEMENT_SPECIFIC_CONTAINER | SQL_FORM_ELEMENT_ALL_CONTAINER
* @param array $param Parameter which matches the prepared statement in $sql
* @param array $formSpec Main FormSpec to copy generic parameter to FormElements
* @return array|int
* @throws \qfq\CodeException
* @throws \qfq\DbException
*/
public function getNativeFormElements($sql, array $param, $formSpec) {
$feSpecNative = $this->sql($sql, ROW_REGULAR, $param);
// Explode and Do $FormElement.parameter
HelperFormElement::explodeParameterInArrayElements($feSpecNative);
// Check for retype FormElements which have to duplicated.
$feSpecNative = HelperFormElement::duplicateRetypeElements($feSpecNative);
// Copy Attributes to FormElements
$this->feSpecNative = HelperFormElement::copyAttributesToFormElements($formSpec, $feSpecNative);
return $feSpecNative;
}
}
\ No newline at end of file
......@@ -244,8 +244,8 @@ class QuickFormQuery {
}
$recordId = $this->store->getVar(SIP_RECORD_ID, STORE_SIP . STORE_TYPO3 . STORE_CLIENT);
// For 'new' record always create a new TAB-uniq (for this current form, nowhere else used) SIP.
// With such a TAB-uniq SIP, multiple TABs and following repeated NEWs are easily implemented.
// For 'new' record always create a new Browser TAB-uniq (for this current form, nowhere else used) SIP.
// With such a Browser TAB-uniq SIP, multiple Browser TABs and following repeated NEWs are easily implemented.
if (!$sipFound || ($formMode == FORM_LOAD && $recordId == 0)) {
$this->store->createSipAfterFormLoad($formName);
}
......@@ -405,14 +405,15 @@ class QuickFormQuery {
// "SELECT *, ? AS 'nestedInFieldSet' FROM FormElement AS fe WHERE fe.formId = ? AND fe.deleted = 'no' AND FIND_IN_SET(fe.class, ? ) AND fe.feIdContainer = ? AND fe.enabled='yes' ORDER BY fe.ord, fe.id";
switch ($mode) {
case FORM_LOAD:
$this->feSpecNative = $this->db->sql(SQL_FORM_ELEMENT_SPECIFIC_CONTAINER, ROW_REGULAR,
['no', $this->formSpec["id"], 'native,container', 0]);
$this->feSpecNative = $this->db->getNativeFormElements(SQL_FORM_ELEMENT_SPECIFIC_CONTAINER,
['no', $this->formSpec["id"], 'native,container', 0], $this->formSpec);
break;
case FORM_SAVE:
case FORM_UPDATE:
$this->feSpecNative = $this->db->sql(SQL_FORM_ELEMENT_ALL_CONTAINER, ROW_REGULAR,
['no', $this->formSpec["id"], 'native']);
$this->feSpecNative = $this->db->getNativeFormElements(SQL_FORM_ELEMENT_ALL_CONTAINER,
['no', $this->formSpec["id"], 'native'], $this->formSpec);
break;
case FORM_DELETE:
......@@ -423,12 +424,6 @@ class QuickFormQuery {
break;
}
// Expand F_FE_PARAMETER ('parameter')
HelperFormElement::explodeParameterInArrayElements($this->feSpecNative);
$this->feSpecNative = $this->copyAttributesToFormElements($this->formSpec, $this->feSpecNative);
$this->feSpecNative = HelperFormElement::duplicateRetypeElements($this->feSpecNative);
return $formName;
}
......@@ -554,24 +549,6 @@ class QuickFormQuery {
return $formSpec;
}
/**
* Copy specific attributes defined on the form to all FormElements.
*
* @param array $formSpec
* @param array $feSpecNative
* @return mixed
*/
private function copyAttributesToFormElements(array $formSpec, array $feSpecNative) {
foreach ($feSpecNative as $key => $element) {
Support::setIfNotSet($feSpecNative[$key], F_FE_DATA_PATTERN_ERROR, $formSpec[F_FE_DATA_PATTERN_ERROR]);
Support::setIfNotSet($feSpecNative[$key], F_FE_DATA_REQUIRED_ERROR, $formSpec[F_FE_DATA_REQUIRED_ERROR]);
Support::setIfNotSet($feSpecNative[$key], F_FE_DATA_MATCH_ERROR, $formSpec[F_FE_DATA_MATCH_ERROR]);
Support::setIfNotSet($feSpecNative[$key], F_FE_DATA_ERROR, $formSpec[F_FE_DATA_ERROR]);
}
return $feSpecNative;
}
/**
* Check if loading of the given form is permitted. If not, throw an exception.
*
......
......@@ -131,4 +131,22 @@ class HelperFormElement
return $arr;
}
/**
* Copy specific attributes defined on the form to all FormElements.
*
* @param array $formSpec
* @param array $feSpecNative
* @return mixed
*/
public static function copyAttributesToFormElements(array $formSpec, array $feSpecNative) {
foreach ($feSpecNative as $key => $element) {
Support::setIfNotSet($feSpecNative[$key], F_FE_DATA_PATTERN_ERROR, $formSpec[F_FE_DATA_PATTERN_ERROR]);
Support::setIfNotSet($feSpecNative[$key], F_FE_DATA_REQUIRED_ERROR, $formSpec[F_FE_DATA_REQUIRED_ERROR]);
Support::setIfNotSet($feSpecNative[$key], F_FE_DATA_MATCH_ERROR, $formSpec[F_FE_DATA_MATCH_ERROR]);
Support::setIfNotSet($feSpecNative[$key], F_FE_DATA_ERROR, $formSpec[F_FE_DATA_ERROR]);
}
return $feSpecNative;
}
}
\ No newline at end of file
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