Commit 7de0d4e3 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Feature #4015: fillStoreVar - should work now

parent 1c6589aa
......@@ -515,7 +515,7 @@ abstract class AbstractBuildForm {
$html = '';
// The following 'FormElement.parameter' will never be used during load (fe.type='upload'). FE_PARAMETER has been already expanded.
$skip = [FE_SQL_UPDATE, FE_SQL_INSERT, FE_SQL_DELETE, FE_SQL_AFTER, FE_SQL_BEFORE, FE_PARAMETER];
$skip = [FE_SQL_UPDATE, FE_SQL_INSERT, FE_SQL_DELETE, FE_SQL_AFTER, FE_SQL_BEFORE, FE_PARAMETER, FE_FILL_STORE_VAR];
// get current data record
if ($recordId > 0 && $this->store->getVar('id', STORE_RECORD) === false) {
......@@ -561,14 +561,16 @@ abstract class AbstractBuildForm {
$fe[FE_VALUE] = $this->processReportSyntax($fe[FE_VALUE]);
$fe[FE_NOTE] = $this->processReportSyntax($fe[FE_NOTE]);
if (isset($fe[FE_FILL_STORE_VAR])) {
$fe[FE_FILL_STORE_VAR]=$this->evaluate->parse($fe[FE_FILL_STORE_VAR]);
$this->store->appendToStore(STORE_VAR, $fe[FE_FILL_STORE_VAR]);
}
// ** evaluate current FormElement **
$formElement = $this->evaluate->parseArray($fe, $skip, $debugStack);
$formElement = HelperFormElement::setLanguage($formElement, $parameterLanguageFieldName);
if (isset($formElement[FE_FILL_STORE_VAR])) {
$this->store->appendToStore(STORE_VAR, $formElement[FE_FILL_STORE_VAR]);
}
// Some Defaults
$formElement = Support::setFeDefaults($formElement, $this->formSpec);
......
......@@ -637,8 +637,14 @@ class QuickFormQuery {
$parseLater = OnArray::getArrayItems($form, [F_FORWARD_PAGE]);
$form[F_FORWARD_PAGE] = '';
HelperFormElement::explodeParameter($form, F_PARAMETER);
unset($form[F_PARAMETER]);
if (isset($form[FE_FILL_STORE_VAR])) {
$fillStoreVar = $form[FE_FILL_STORE_VAR];
unset($form[FE_FILL_STORE_VAR]);
}
$formSpec = $this->eval->parseArray($form);
HelperFormElement::explodeParameter($formSpec, F_PARAMETER);
// Setting defaults later is to late.
if (!isset($formSpec[F_DB_INDEX_DATA])) {
......@@ -664,10 +670,22 @@ class QuickFormQuery {
// Set F_FINAL_DELETE_FORM
$formSpec[F_FINAL_DELETE_FORM] = ($formSpec[F_EXTRA_DELETE_FORM] != '') ? $formSpec[F_EXTRA_DELETE_FORM] : $formSpec[F_NAME];
$this->formSpec = $formSpec;
// this is needed for filling templateGroup records with their default values
$this->fillStoreWithRecord($this->formSpec[F_TABLE_NAME], $recordId, STORE_RECORD);
$this->fillStoreWithRecord($formSpec[F_TABLE_NAME], $recordId, STORE_RECORD);
// Fire FE_FILL_STORE_VAR after the primary form record has been loaded
if (!empty($fillStoreVar)) {
$rows = $this->eval->parse($fillStoreVar);
if (is_array($rows)) {
$this->store->appendToStore(STORE_VAR, $rows[0]);
} else {
if (!empty($rows)) {
throw new UserFormException("Invalid statement for '" . FE_FILL_STORE_VAR . "': " . $formSpec[FE_FILL_STORE_VAR], ERROR_INVALID_OR_MISSING_PARAMETER);
}
}
}
$this->formSpec = $formSpec;
// Clear
$this->store->setVar(SYSTEM_FORM_ELEMENT, '', STORE_SYSTEM);
......
......@@ -287,6 +287,9 @@ class Save {
}
$formElement = HelperFormElement::initUploadFormElement($formElement);
if (isset($formElement[FE_FILL_STORE_VAR])) {
$this->store->appendToStore(STORE_VAR, $formElement[FE_FILL_STORE_VAR]);
}
// Preparation for Log, Debug
$this->store->setVar(SYSTEM_FORM_ELEMENT, Logger::formatFormElementName($formElement), STORE_SYSTEM);
......
......@@ -88,8 +88,16 @@ class FormAction {
continue;
}
if (isset($feSpecAction[FE_FILL_STORE_VAR])) {
$this->store->appendToStore(STORE_VAR, $feSpecAction[FE_FILL_STORE_VAR]);
if (isset($fe[FE_FILL_STORE_VAR])) {
$rows = $this->evaluate->parse($fe[FE_FILL_STORE_VAR]);
if (is_array($rows)) {
$this->store->appendToStore(STORE_VAR, $rows[0]);
} else {
if (!empty($rows)) {
throw new UserFormException("Invalid statement for 'fillStoreVar': " . $fe[FE_FILL_STORE_VAR], ERROR_INVALID_OR_MISSING_PARAMETER);
}
}
$fe[FE_FILL_STORE_VAR] = ''; // do not process the same later on.
}
// Process templateGroup action elements
......
......@@ -19,7 +19,7 @@ class HelperFormElement {
/**
* Expand column $keyName to row array as virtual columns.
* E.g.: [ 'id' => '1', 'name' => 'John', 'parameter' => 'detail=xId:grId\nShowEmptyAtStart=1' ] beocmes:
* E.g.: [ 'id' => '1', 'name' => 'John', 'parameter' => 'detail=xId:grId\nShowEmptyAtStart=1' ] becomes:
* [ 'id' => '1', 'name' => 'John', 'parameter' => 'detail=xId:grId\nShowEmptyAtStart=1', 'detail' => 'xId:grId',
* 'showEmptyAtStart'='1']
*
......
......@@ -848,7 +848,7 @@ class Store {
*/
public static function appendToStore($storeName, array $values) {
if (is_array($values[0])) {
if (isset($values[0]) && is_array($values[0])) {
$append = $values[0];
} else {
$append = $values;
......
Markdown is supported
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