Commit 6479c9f7 authored by Carsten  Rose's avatar Carsten Rose
Browse files

*.php: extend explodeParameter(), explodeParameterInArrayElements() with...

*.php: extend explodeParameter(), explodeParameterInArrayElements() with argument $keyName, to make it more generic.
parent 881cca2b
......@@ -352,7 +352,7 @@ abstract class AbstractBuildForm {
$flagOutput = false;
// The following 'FormElement.parameter' will never be used during load (fe.type='upload').
$skip = [FE_SQL_UPDATE, FE_SQL_INSERT, FE_SQL_DELETE, FE_SQL_AFTER, FE_SQL_BEFORE, F_FE_PARAMETER];
$skip = [FE_SQL_UPDATE, FE_SQL_INSERT, FE_SQL_DELETE, FE_SQL_AFTER, FE_SQL_BEFORE, FE_PARAMETER];
// get current data record
if ($recordId > 0 && $this->store->getVar('id', STORE_RECORD) === false) {
......@@ -1926,7 +1926,7 @@ abstract class AbstractBuildForm {
* Returns <a href="<Link>">[icon]</a>
*
* Link: <page>?s=<SIP>&<standard typo3 params>
* SIP: form = $formElement['form'] (provided via formElement['parameter'])
* SIP: form = $formElement['form'] (provided via formElement[FE_PARAMETER])
* r = $targetRecordId
* Parse $formElement['detail'] with possible key/value pairs. E.g.: detail=id:gr_id,#{{a}}:p_id,#12:x_id
* gr_id = <<primarytable.id>>
......
......@@ -491,6 +491,8 @@ const F_FE_DATA_REQUIRED_ERROR = 'data-required-error';
const F_FE_DATA_MATCH_ERROR = 'data-match-error';
const F_FE_DATA_ERROR = 'data-error';
const F_PARAMETER = 'parameter'; // valid for F_ and FE_
// FORM_ELEMENT_STATI
const FE_MODE_SHOW = 'show';
......@@ -522,7 +524,7 @@ const FE_BS_INPUT_COLUMNS = F_BS_INPUT_COLUMNS;
const FE_BS_NOTE_COLUMNS = F_BS_NOTE_COLUMNS;
const FE_WRAP_ROW_LABEL_INPUT_NOW = 'rowLabelInputNote';
const FE_MAX_LENGTH = 'maxLength';
const F_FE_PARAMETER = 'parameter'; // valid for F_ and FE_
const FE_PARAMETER = 'parameter';
// FormElement columns: via parameter field
......
......@@ -632,7 +632,7 @@ class Database {
$feSpecNative = $this->sql($sql, ROW_REGULAR, $param);
// Explode and Do $FormElement.parameter
HelperFormElement::explodeParameterInArrayElements($feSpecNative);
HelperFormElement::explodeParameterInArrayElements($feSpecNative, FE_PARAMETER);
// Check for retype FormElements which have to duplicated.
$feSpecNative = HelperFormElement::duplicateRetypeElements($feSpecNative);
......
......@@ -285,6 +285,7 @@ class QuickFormQuery {
switch ($formMode) {
case FORM_LOAD:
case FORM_UPDATE:
$formAction->elements($recordId, $this->feSpecAction, FE_TYPE_BEFORE_LOAD);
$data = $build->process($formMode);
$formAction->elements($recordId, $this->feSpecAction, FE_TYPE_AFTER_LOAD);
......@@ -389,7 +390,7 @@ class QuickFormQuery {
$form = $this->modeCleanFormConfig($mode, $form);
$formSpec = $this->eval->parseArray($form);
HelperFormElement::explodeParameter($formSpec);
HelperFormElement::explodeParameter($formSpec, F_PARAMETER);
$formSpec = $this->syncSystemFormConfig($formSpec);
$formSpec = $this->initForm($formSpec);
......@@ -404,7 +405,7 @@ class QuickFormQuery {
// FE: Action
$this->feSpecAction = $this->db->sql(SQL_FORM_ELEMENT_ALL_CONTAINER, ROW_REGULAR, ['no', $this->formSpec["id"], 'action']);
HelperFormElement::explodeParameterInArrayElements($this->feSpecAction);
HelperFormElement::explodeParameterInArrayElements($this->feSpecAction, FE_PARAMETER);
// FE: Native & Container
// "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";
......
......@@ -21,41 +21,41 @@ class HelperFormElement
{
/**
* Expand column 'parameter' to row array as virtual columns.
* E.g.: 'detail=xId:grId\nShowEmptyAtStart=1`
*
* Expand column $keyName to row array as virtual columns.
* E.g.: [ 'id' => '1', 'name' => 'John', 'parameter' => 'detail=xId:grId\nShowEmptyAtStart=1' ] beocmes:
* [ 'id' => '1', 'name' => 'John', 'parameter' => 'detail=xId:grId\nShowEmptyAtStart=1', 'detail' => 'xId:grId', 'showEmptyAtStart'='1']
* @param array $elements
* @param string $keyName Typically F_PARAMETER or FE_PARAMETER (both: 'parameter')
* @throws \qfq\UserFormException
*/
public static function explodeParameterInArrayElements(array &$elements) {
public static function explodeParameterInArrayElements(array &$elements, $keyName) {
foreach ($elements AS $key => $element) {
self::explodeParameter($element);
self::explodeParameter($element, $keyName);
$elements[$key] = $element;
}
}
/**
* Take all rows from field $element['parameter'] and merge them with $element. '$element' grows in size.
*
* Iterates over all FormElements in $elements.
* If $element['parameter'] exist and is filled: explode the content and append them to the current array.
* Take all rows from field $element[$keyName] and merge them with $element itself. '$element' grows in size.
*
* @param array $elements
* @throws UserFormException
* @param array $element
* @param string $keyName Typically F_PARAMETER or FE_PARAMETER (both: 'parameter')
* @throws CodeException
* @throws \qfq\UserFormException
*/
public static function explodeParameter(array &$element)
public static function explodeParameter(array &$element, $keyName)
{
// Something to explode?
if (isset($element[F_FE_PARAMETER]) && $element[F_FE_PARAMETER] !== '') {
if (isset($element[$keyName]) && $element[$keyName] !== '') {
// Explode
$arr = KeyValueStringParser::parse($element[F_FE_PARAMETER], "=", "\n");
$arr = KeyValueStringParser::parse($element[$keyName], "=", "\n");
// Check if some of the exploded keys conflict with existing keys
$checkKeys = array_keys($arr);
foreach ($checkKeys AS $checkKey) {
if (isset($element[$checkKey])) {
$store = Store::getInstance();
$store->setVar(SYSTEM_FORM_ELEMENT, Logger::formatFormElementName($element), STORE_SYSTEM);
$store->setVar(SYSTEM_FORM_ELEMENT_COLUMN, F_FE_PARAMETER, STORE_SYSTEM);
$store->setVar(SYSTEM_FORM_ELEMENT_COLUMN, $keyName, STORE_SYSTEM);
throw new UserFormException("Found reserved keyname '$checkKey'", ERROR_RESERVED_KEY_NAME);
}
}
......
......@@ -64,10 +64,10 @@ class FillStoreForm {
$feSpecNative = $this->db->sql(SQL_FORM_ELEMENT_SIMPLE_ALL_CONTAINER, ROW_EXPECT_GE_1, [$formName],
'Form or FormElements not found: ' . ERROR_FORM_NOT_FOUND);
HelperFormElement::explodeParameterInArrayElements($feSpecNative);
HelperFormElement::explodeParameterInArrayElements($feSpecNative, FE_PARAMETER);
$feSpecTemplateGroup = $this->db->sql(SQL_FORM_ELEMENT_CONTAINER_TEMPLATE_GROUP, ROW_REGULAR, [$formName]);
HelperFormElement::explodeParameterInArrayElements($feSpecTemplateGroup);
HelperFormElement::explodeParameterInArrayElements($feSpecTemplateGroup, FE_PARAMETER);
$feSpecNative = $this->expandTemplateGroupFormElement($feSpecTemplateGroup, $feSpecNative);
......@@ -130,7 +130,7 @@ class FillStoreForm {
*/
public function process() {
// The following will never be used during load (fe.type='upload').
$skip = [FE_SQL_UPDATE, FE_SQL_INSERT, FE_SQL_DELETE, FE_SQL_AFTER, FE_SQL_BEFORE, F_FE_PARAMETER];
$skip = [FE_SQL_UPDATE, FE_SQL_INSERT, FE_SQL_DELETE, FE_SQL_AFTER, FE_SQL_BEFORE, FE_PARAMETER];
$html = '';
$newValues = array();
......
......@@ -19,25 +19,25 @@ class HelperFormElementTest extends \PHPUnit_Framework_TestCase {
public function testExplodeParameter() {
$a = array();
HelperFormElement::explodeParameter($a);
HelperFormElement::explodeParameter($a, FE_PARAMETER);
$this->assertEquals(array(), $a, "Both arrays should be equal and empty");
$a = ['id' => 100, 'parameter' => "work=12\nlist=1:new,2:edit,3:delete"];
$b = ['id' => 100, 'parameter' => "work=12\nlist=1:new,2:edit,3:delete", 'work' => 12, 'list' => '1:new,2:edit,3:delete'];
HelperFormElement::explodeParameter($a);
HelperFormElement::explodeParameter($a, FE_PARAMETER);
$this->assertEquals($b, $a, "Both arrays should be equal");
}
public function testExplodeParameterInArrayElements() {
$a = array();
HelperFormElement::explodeParameterInArrayElements($a);
HelperFormElement::explodeParameterInArrayElements($a, FE_PARAMETER);
$this->assertEquals(array(), $a, "Both arrays should be equal and empty");
$a = [0 => ['id' => 100, 'parameter' => "work=12\nlist=1:new,2:edit,3:delete"]];
$b = [0 => ['id' => 100, 'parameter' => "work=12\nlist=1:new,2:edit,3:delete", 'work' => 12, 'list' => '1:new,2:edit,3:delete']];
HelperFormElement::explodeParameterInArrayElements($a);
HelperFormElement::explodeParameterInArrayElements($a, FE_PARAMETER);
$this->assertEquals($b, $a, "Both arrays should be equal");
}
......@@ -49,7 +49,7 @@ class HelperFormElementTest extends \PHPUnit_Framework_TestCase {
public function testExplodeFieldParameterException() {
$a = [0 => ['id' => 111, 'name' => 'hello', 'collision' => 'dummy', 'parameter' => "work=12\ncollision=1:new,2:edit,3:delete"]];
HelperFormElement::explodeParameterInArrayElements($a);
HelperFormElement::explodeParameterInArrayElements($a, FE_PARAMETER);
}
......
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