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

#4278 / Language: Check that language settings respect inside of container /...

#4278 / Language: Check that language settings respect inside of container / pill / fieldset / templateGroup
HelperFormElement.php,AbstractBuildForm.php,BuildFormBootstrap.php,QuickFormQuery.php: function setLanguage() moved from QuickFormQuery.php to HelperFormElement.php
parent 86e86462
......@@ -470,6 +470,8 @@ abstract class AbstractBuildForm {
$this->checkAutoFocus();
$parameterLanguageFieldName = $this->store->getVar(SYSTEM_PARAMETER_LANGUAGE_FIELD_NAME, STORE_SYSTEM);
// Iterate over all FormElements
foreach ($this->feSpecNative as $fe) {
$storeUse = $storeUseDefault;
......@@ -506,6 +508,7 @@ abstract class AbstractBuildForm {
// ** evaluate current FormElement **
$formElement = $this->evaluate->parseArray($fe, $skip, $debugStack);
$formElement = HelperFormElement::setLanguage($formElement, $parameterLanguageFieldName);
// Some Defaults
$formElement = Support::setFeDefaults($formElement, $this->formSpec);
......@@ -3194,7 +3197,6 @@ abstract class AbstractBuildForm {
['yes', $this->formSpec["id"], 'native,container', $formElement[FE_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];
$html .= '</fieldset>';
......@@ -3214,6 +3216,7 @@ abstract class AbstractBuildForm {
* @return array
*/
private function fillFeSpecNativeCheckboxWithTgMax(array $formElementArr, $tgMaxCopies) {
foreach ($formElementArr as $key => $formElement) {
if ($formElement[FE_TYPE] = FE_TYPE_CHECKBOX) {
$formElementArr[$key][NAME_TG_COPIES] = $tgMaxCopies;
......@@ -3286,7 +3289,7 @@ EOT;
// Count defined FormElements in the current templateGroup
$elementsTotal = count($this->feSpecNative);
if ($elementsTotal < 1) {
// Nothting to do: return.
// Nothing to do: return.
$this->feSpecNative = $feSpecNativeSave;
return '';
......
......@@ -376,10 +376,17 @@ class BuildFormBootstrap extends AbstractBuildForm {
$maxVisiblePill = (isset($this->formSpec['maxVisiblePill']) && $this->formSpec['maxVisiblePill'] !== '') ? $this->formSpec['maxVisiblePill'] : 1000;
$parameterLanguageFieldName = $this->store->getVar(SYSTEM_PARAMETER_LANGUAGE_FIELD_NAME, STORE_SYSTEM);
// Iterate over all 'pill'
$ii = 0;
$active = 'class="active"';
foreach ($pillArray as $formElement) {
$formElement = $this->evaluate->parseArray($formElement);
HelperFormElement::explodeParameter($formElement, F_PARAMETER);
$formElement = HelperFormElement::setLanguage($formElement, $parameterLanguageFieldName);
$ii++;
if ($formElement[FE_NAME] === '' || $formElement[FE_LABEL] === '') {
......
......@@ -479,6 +479,7 @@ const DOWNLOAD_POPUP_REQUEST = 'true';
const DOWNLOAD_POPUP_REPLACE_TEXT = '#downloadPopupReplaceText#';
const DOWNLOAD_POPUP_REPLACE_TITLE = '#downloadPopupReplaceTitle#';
const SYSTEM_PARAMETER_LANGUAGE_FIELD_NAME = 'parameterLanguageFieldName';
const CSS_REQUIRED = 'required-field';
// die folgenden Elemente sind vermutlich nicht noetig, wenn Store Klassen gloable Vars benutzt.
......
......@@ -111,11 +111,12 @@ class QuickFormQuery {
/**
* Construct the Form Class and Store too. This is the base initialization moment.
*
* As a result of instantiating of Form, the class Store will initially called the first time and therefore instantiated automatically.
* Store might throw an exception, in case the URL-passed SIP is invalid.
* As a result of instantiating of Form, the class Store will initially called the first time and therefore
* instantiated automatically. Store might throw an exception, in case the URL-passed SIP is invalid.
*
* @param array $t3data
* @param bool $phpUnit
* @param bool $phpUnit
*
* @throws CodeException
* @throws UserFormException
*/
......@@ -211,6 +212,25 @@ class QuickFormQuery {
return $html;
}
/**
* Determine the name of the language parameter field, which has to be taken to fill language specific defintions.
*/
private function setParameterLanguageFieldName() {
$typo3PageLanguage = $this->store->getVar(TYPO3_PAGE_LANGUAGE, STORE_TYPO3);
if (empty($typo3PageLanguage)) {
return;
}
foreach (['A', 'B', 'C', 'D'] as $key) {
$languageIdx = SYSTEM_FORM_LANGUAGE . "_$key" . "_ID";
if ($this->store->getVar($languageIdx, STORE_SYSTEM) == $typo3PageLanguage) {
$this->store->setVar(SYSTEM_PARAMETER_LANGUAGE_FIELD_NAME, 'parameterLanguage' . $key, STORE_SYSTEM);
break;
}
}
}
/**
* Process form.
* $mode=
......@@ -220,6 +240,7 @@ class QuickFormQuery {
* FORM_DELETE:
*
* @param string $formMode FORM_LOAD | FORM_UPDATE | FORM_SAVE | FORM_DELETE
*
* @return array|string
* @throws CodeException
* @throws UserFormException
......@@ -235,6 +256,7 @@ class QuickFormQuery {
}
$recordId = $this->store->getVar(SIP_RECORD_ID, STORE_SIP . STORE_TYPO3 . STORE_CLIENT . STORE_ZERO);
$this->setParameterLanguageFieldName();
$formName = $this->loadFormSpecification($formMode, $recordId, $foundInStore);
if ($formName === false && $formMode !== FORM_DELETE) {
......@@ -277,6 +299,7 @@ class QuickFormQuery {
// In case of a conflict, return immediately
if ($answer[API_STATUS] != API_ANSWER_STATUS_SUCCESS) {
$answer[API_STATUS] = API_ANSWER_STATUS_ERROR;
return $answer;
}
}
......@@ -409,8 +432,9 @@ class QuickFormQuery {
/**
* Iterate over all Clipboard source records and fire for each all FE.type=paste records.
*
* @param int $formId
* @param int $formId
* @param FormAction $formAction
*
* @throws CodeException
* @throws DbException
* @throws UserFormException
......@@ -447,6 +471,7 @@ class QuickFormQuery {
return true;
}
}
return false;
}
......@@ -456,7 +481,8 @@ class QuickFormQuery {
* used parameters. Do this by building a new SIP with the new recordId.
*
* @param array $formSpec
* @param int $recordId
* @param int $recordId
*
* @return array
* @throws CodeException
* @throws UserFormException
......@@ -490,8 +516,9 @@ class QuickFormQuery {
* Loaded 'native' FormElements are in $this->feSpecNative
*
* @param string $mode FORM_LOAD|FORM_SAVE|FORM_UPDATE
* @param int $recordId
* @param int $recordId
* @param string $foundInStore
*
* @return bool|string if found the formName, else 'false'.
* @throws CodeException
* @throws DbException
......@@ -530,7 +557,9 @@ class QuickFormQuery {
$formSpec = $this->eval->parseArray($form);
HelperFormElement::explodeParameter($formSpec, F_PARAMETER);
$formSpec = $this->setLanguage($formSpec);
$parameterLanguageFieldName = $this->store->getVar(SYSTEM_PARAMETER_LANGUAGE_FIELD_NAME, STORE_SYSTEM);
$formSpec = HelperFormElement::setLanguage($formSpec, $parameterLanguageFieldName);
$formSpec = $this->syncSystemFormConfig($formSpec);
$formSpec = $this->initForm($formSpec);
......@@ -575,47 +604,20 @@ class QuickFormQuery {
break;
}
$this->feSpecNative = $this->setLanguage($feSpecNative);
$this->feSpecNative = HelperFormElement::setLanguage($feSpecNative, $parameterLanguageFieldName);
return $formName;
}
/**
* @param array $formSpec
* @return array
* @throws UserFormException
*/
private function setLanguage(array $formSpec) {
$typo3PageLanguage = $this->store->getVar(TYPO3_PAGE_LANGUAGE, STORE_TYPO3);
if (empty($typo3PageLanguage)) {
return $formSpec;
}
foreach (['A', 'B', 'C', 'D'] as $key) {
$languageIdx = SYSTEM_FORM_LANGUAGE . "_$key" . "_ID";
if ($this->store->getVar($languageIdx, STORE_SYSTEM) == $typo3PageLanguage) {
$parameterField = 'parameterLanguage' . $key;
break;
}
}
if (!isset($parameterField)) {
throw new UserFormException("Language not configured in QFQ for L=" . $typo3PageLanguage, ERROR_LANGUAGE_NOT_CONFIGURED_IN_QFQ);
}
HelperFormElement::explodeParameter($formSpec, $parameterField, true);
return $formSpec;
}
/**
* Depending on $sql reads FormElements to a specific container or all. Preprocess all FormElements.
* This code is dirty: the nearly same function exists in class 'Database' - the difference is only 'explodeTemplateGroupElements()'.
* This code is dirty: the nearly same function exists in class 'Database' - the difference is only
* 'explodeTemplateGroupElements()'.
*
* @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
*
* @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
......@@ -642,16 +644,18 @@ class QuickFormQuery {
}
/**
* Iterate over all FormElements in $elements. If a row has a column NAME_TG_COPIES, copy those elements NAME_TG_COPIES-times.
* Adjust FE_TEMPLATE_GROUP_NAME_PATTERN (='%d') with current count on column FE_NAME and FE_LABEL.
* Iterate over all FormElements in $elements. If a row has a column NAME_TG_COPIES, copy those elements
* NAME_TG_COPIES-times. Adjust FE_TEMPLATE_GROUP_NAME_PATTERN (='%d') with current count on column FE_NAME and
* FE_LABEL.
*
* This code is dirty: only to get JSON value, we have to initialize the STORE_RECORD (done earlier) to be capable to
* parse fe[FE_VALUE], which probably contains as string like '{{!SELECT value FROM table WHERE xId={{id}} ORDER BY id}}' -
* the {{id}} needs to be replaced by the current recordId (primary record).
* This code is dirty: only to get JSON value, we have to initialize the STORE_RECORD (done earlier) to be capable
* to parse fe[FE_VALUE], which probably contains as string like '{{!SELECT value FROM table WHERE xId={{id}} ORDER
* BY id}}' - the {{id}} needs to be replaced by the current recordId (primary record).
*
* Attention: The resulting order of the FormElements, is not the same as on the Form during FormLoad!
*
* @param array $elements
*
* @return array
*/
private function explodeTemplateGroupElements(array $elements) {
......@@ -680,6 +684,7 @@ class QuickFormQuery {
$new[] = $row;
}
}
return $new;
}
......@@ -691,9 +696,9 @@ class QuickFormQuery {
* Specified in T3 body text with form=<formname> Returned Store:Typo3
* Specified in T3 body text with form={{form}} ':FSRD' Returned Store:SIP
* Specified in T3 body text with form={{form:C:ALNUMX}} Returned Store:Client
* Specified in T3 body text with form={{SELECT registrationFormName FROM Conference WHERE id={{conferenceId:S0}} }}
* Specified in T3 body text with form={{SELECT registrationFormName FROM Conference WHERE id={{conferenceId:C0:DIGIT}} }}
* Specified in SIP
* Specified in T3 body text with form={{SELECT registrationFormName FROM Conference WHERE id={{conferenceId:S0}}
* }} Specified in T3 body text with form={{SELECT registrationFormName FROM Conference WHERE
* id={{conferenceId:C0:DIGIT}} }} Specified in SIP
*
* FORM_SAVE:
* Specified in SIP
......@@ -701,6 +706,7 @@ class QuickFormQuery {
*
* @param string $mode FORM_LOAD|FORM_SAVE|FORM_UPDATE
* @param string $foundInStore
*
* @return bool|string Formname (Form.name) or FALSE (if no formname found)
* @throws CodeException
* @throws UserFormException
......@@ -745,7 +751,8 @@ class QuickFormQuery {
* E.g.: the form title is not important during a delete.
*
* @param string $mode
* @param array $form
* @param array $form
*
* @return array
*/
private function modeCleanFormConfig($mode, array $form) {
......@@ -770,6 +777,7 @@ class QuickFormQuery {
* corresponding inputfield.
*
* @param array $formSpec
*
* @return array
*/
private function syncSystemFormConfig(array $formSpec) {
......@@ -836,6 +844,7 @@ class QuickFormQuery {
* Set form parameter which are expected to exist.
*
* @param array $formSpec
*
* @return array
*/
private function initForm(array $formSpec) {
......@@ -862,6 +871,7 @@ class QuickFormQuery {
*
* @param string $formNameFoundInStore
* @param string $formMode
*
* @return bool 'true' if SIP exists, else 'false'
* @throws \qfq\CodeException
* @throws \qfq\UserFormException
......@@ -949,6 +959,7 @@ class QuickFormQuery {
* @param string $table tablename from where to load record wiht $recordId
* @param string $recordId record ID of current record
* @param string $store name of store where to save the record
*
* @throws CodeException
* @throws DbException
* @throws UserFormException
......@@ -965,6 +976,7 @@ class QuickFormQuery {
* All found elements collect under $collect[API_ELEMENT_UPDATE]... . Leave the rest unchanged.
*
* @param array $dataArray
*
* @return array to build JSON
*/
private function groupElementUpdateEntries(array $dataArray) {
......@@ -1045,7 +1057,7 @@ class QuickFormQuery {
* Based on the given SIP, create a new uniqe SIP by copying the relevant old params and taking the new recordId..
*
* @param array $sipArray
* @param int $recordId
* @param int $recordId
*/
private function newRecordCreateSip(array $sipArray, $recordId) {
......
......@@ -77,6 +77,22 @@ class HelperFormElement {
}
}
/**
* Take language specific definitions and overwrite the default values.
*
* @param array $formSpecFeSpecNative
*
* @return array
* @throws UserFormException
*/
public static function setLanguage(array $formSpecFeSpecNative, $parameterLanguageFieldName) {
if (is_string($parameterLanguageFieldName) && isset($formSpecFeSpecNative[$parameterLanguageFieldName])) {
self::explodeParameter($formSpecFeSpecNative, $parameterLanguageFieldName, true);
}
return $formSpecFeSpecNative;
}
/**
* Build the FE name: <field>-<record index)
*
......
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