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

AdminstratorManual/Index.rst: Update config.qfq.ini description to new...

AdminstratorManual/Index.rst: Update config.qfq.ini description to new parameter 'class'. Remove 'DB_NAME_TEST' cause that is only interesting to PHP Unit Tests and not to enduser.
UserManual/Index.rst: Update STORE_SYSTEM description of known variables.
Store.php, QuickFormQuery.php: Refactor building STORE_SYSTEM. Make it more generic if new parameters are introduced. Setting up new config.qfq.ini built in defaults and form defaults at one place. Renaming of parameter names in config.qfq.ini to STORE_SYSTEM at one place implemented with an extensible array.
AbstractBuildForm.php, BuildFormBootstrap.php, BuildFormTable.php: User constant F_CLASS  in $this->formSpec['class']
config.qfq.example.ini: comment empty variables - the new default setting is, that empty parameter in config.qfq.ini means EMPTY, not UNDEFINED.
parent 96fd3c00
......@@ -164,19 +164,19 @@ Example: *typo3conf/config.qfq.ini*
DB_SERVER = localhost
DB_PASSWORD = 12345678
DB_NAME = qfq_db
DB_NAME_TEST = qfq_db_test
DB_INIT = set names utf8
SQL_LOG = sql.log
SHOW_DEBUG_INFO = auto
CSS_LINK_CLASS_INTERNAL = internal
CSS_LINK_CLASS_EXT = external
CSS_CLASS_QFQ_CONTAINER =
;CSS_CLASS_QFQ_CONTAINER =
;CSS_CLASS_QFQ_FORM =
CSS_CLASS_QFQ_FORM_PILL = qfq-color-grey-1
CSS_CLASS_QFQ_FORM_BODY = qfq-color-grey-2
FORM_DATA_PATTERN_ERROR =
FORM_DATA_REQUIRED_ERROR =
FORM_DATA_MATCH_ERROR =
FORM_DATA_ERROR =
;FORM_DATA_PATTERN_ERROR =
;FORM_DATA_REQUIRED_ERROR =
;FORM_DATA_MATCH_ERROR =
;FORM_DATA_ERROR =
Documentation
-------------
......
......@@ -425,49 +425,61 @@ Store: *VARS* - V
Store: *SYSTEM* - Y
^^^^^^^^^^^^^^^^^^^
+-------------------------+------------------------------------------------------------+
| Name | Explanation |
+=========================+============================================================+
| DB_USER | defined in config.ini |
+-------------------------+------------------------------------------------------------+
| DB_SERVER | defined in config.ini |
+-------------------------+------------------------------------------------------------+
| DB_NAME | defined in config.ini |
+-------------------------+------------------------------------------------------------+
| DB_INIT | defined in config.ini |
+-------------------------+------------------------------------------------------------+
| SQL_LOG | defined in config.ini |
+-------------------------+------------------------------------------------------------+
| SQL_LOG_MODE | defined in config.ini |
+-------------------------+------------------------------------------------------------+
| SHOW_DEBUG_INFO | defined in config.ini |
+-------------------------+------------------------------------------------------------+
| CSS_LINK_CLASS_INTERNAL | defined in config.ini |
+-------------------------+------------------------------------------------------------+
| CSS_LINK_CLASS_EXTERNAL | defined in config.ini |
+-------------------------+------------------------------------------------------------+
| CSS_CLASS_QFQ_CONTAINER | defined in config.ini |
+-------------------------+------------------------------------------------------------+
| EXT_PATH | computed during runtime |
+-------------------------+------------------------------------------------------------+
| SITE_PATH | computed during runtime |
+-------------------------+------------------------------------------------------------+
| DATE_FORMAT | defined in config.ini |
+-------------------------+------------------------------------------------------------+
| FORM_DATA_PATTERN_ERROR | defined in config.ini |
+-------------------------+------------------------------------------------------------+
| FORM_DATA_REQUIRED_ERROR| defined in config.ini |
+-------------------------+------------------------------------------------------------+
| FORM_DATA_MATCH_ERROR | defined in config.ini |
+-------------------------+------------------------------------------------------------+
| FORM_DATA_ERROR | defined in config.ini |
+-------------------------+------------------------------------------------------------+
| sqlFinal | computed during runtime, used for error reporting |
+-------------------------+------------------------------------------------------------+
| sqlParamArray | computed during runtime, used for error reporting |
+-------------------------+------------------------------------------------------------+
| sqlCount | computed during runtime, used for error reporting |
+-------------------------+------------------------------------------------------------+
+-------------------------+--------------------------------------------------------------------------+
| Name | Explanation |
+=========================+==========================================================================+
| DB_USER | defined in config.ini |
+-------------------------+--------------------------------------------------------------------------+
| DB_SERVER | defined in config.ini |
+-------------------------+--------------------------------------------------------------------------+
| DB_NAME | defined in config.ini |
+-------------------------+--------------------------------------------------------------------------+
| DB_INIT | defined in config.ini |
+-------------------------+--------------------------------------------------------------------------+
| SQL_LOG | defined in config.ini |
+-------------------------+--------------------------------------------------------------------------+
| SQL_LOG_MODE | defined in config.ini |
+-------------------------+--------------------------------------------------------------------------+
| SHOW_DEBUG_INFO | defined in config.ini |
+-------------------------+--------------------------------------------------------------------------+
| CSS_LINK_CLASS_INTERNAL | defined in config.ini |
+-------------------------+--------------------------------------------------------------------------+
| CSS_LINK_CLASS_EXTERNAL | defined in config.ini |
+-------------------------+--------------------------------------------------------------------------+
| CSS_CLASS_QFQ_CONTAINER | defined in config.ini |
+-------------------------+--------------------------------------------------------------------------+
| EXT_PATH | computed during runtime |
+-------------------------+--------------------------------------------------------------------------+
| SITE_PATH | computed during runtime |
+-------------------------+--------------------------------------------------------------------------+
| DATE_FORMAT | defined in config.ini |
+-------------------------+--------------------------------------------------------------------------+
| class | defined in config.ini (CSS_CLASS_QFQ_FORM) or form definition |
+-------------------------+--------------------------------------------------------------------------+
| classPill | defined in config.ini (CSS_CLASS_QFQ_FORM_PILL) or form definition |
+-------------------------+--------------------------------------------------------------------------+
| classBody | defined in config.ini (CSS_CLASS_QFQ_FORM_BODY) or form definition |
+-------------------------+--------------------------------------------------------------------------+
| data-pattern-error | defined in config.ini or form definition |
+-------------------------+--------------------------------------------------------------------------+
| data-require-error | defined in config.ini or form definition |
+-------------------------+--------------------------------------------------------------------------+
| data-match-error | defined in config.ini or form definition |
+-------------------------+--------------------------------------------------------------------------+
| data-error | defined in config.ini or form definition |
+-------------------------+--------------------------------------------------------------------------+
| bsLabelColumns | defined in config.ini (FORM_BS_LABEL_COLUMNS) or form definition |
+-------------------------+--------------------------------------------------------------------------+
| bsInputColumns | defined in config.ini (FORM_BS_INPUT_COLUMNS) or form definition |
+-------------------------+--------------------------------------------------------------------------+
| bsNoteColumns | defined in config.ini (FORM_BS_NOTE_COLUMNS) or form definition |
+-------------------------+--------------------------------------------------------------------------+
| sqlFinal | computed during runtime, used for error reporting |
+-------------------------+--------------------------------------------------------------------------+
| sqlParamArray | computed during runtime, used for error reporting |
+-------------------------+--------------------------------------------------------------------------+
| sqlCount | computed during runtime, used for error reporting |
+-------------------------+--------------------------------------------------------------------------+
SQL Statement
-------------
......
......@@ -22,7 +22,7 @@ CSS_LINK_CLASS_INTERNAL = internal
CSS_LINK_CLASS_EXTERNAL = external
; QFQ with own Bootstrap: 'container'. QFQ already nested in Bootstrap of mainpage: <empty>
CSS_CLASS_QFQ_CONTAINER =
;CSS_CLASS_QFQ_CONTAINER =
; Default background color, specified via CSS class
CSS_CLASS_QFQ_FORM_PILL = qfq-color-grey-1
......@@ -32,12 +32,12 @@ CSS_CLASS_QFQ_FORM_BODY = qfq-color-grey-2
DATE_FORMAT = yyyy-mm-dd
; validator.js: data-pattern-error="", data-required-error="", data-match-error="", data-error=""
FORM_DATA_PATTERN_ERROR =
FORM_DATA_REQUIRED_ERROR =
FORM_DATA_MATCH_ERROR =
FORM_DATA_ERROR =
;FORM_DATA_PATTERN_ERROR =
;FORM_DATA_REQUIRED_ERROR =
;FORM_DATA_MATCH_ERROR =
;FORM_DATA_ERROR =
; Default size for Bootstrap Form Elements
FORM_BS_LABEL_COLUMNS = 3
FORM_BS_INPUT_COLUMNS = 6
FORM_BS_NOTE_COLUMNS = 3
;FORM_BS_LABEL_COLUMNS = 3
;FORM_BS_INPUT_COLUMNS = 6
;FORM_BS_NOTE_COLUMNS = 3
......@@ -196,7 +196,7 @@ abstract class AbstractBuildForm {
public function head() {
$html = '';
$html .= '<div ' . Support::doAttribute('class', $this->formSpec['class'], TRUE) . '>'; // main <div class=...> around everything
$html .= '<div ' . Support::doAttribute('class', $this->formSpec[F_CLASS], TRUE) . '>'; // main <div class=...> around everything
// Logged in BE User will see a FormEdit Link
$sipParamString = OnArray::toString($this->store->getStore(STORE_SIP), ':', ', ', "'");
......
......@@ -101,7 +101,7 @@ class BuildFormBootstrap extends AbstractBuildForm {
public function head() {
$html = '';
$html .= '<div ' . Support::doAttribute('class', $this->formSpec['class'], TRUE) . '>'; // main <div class=...> around everything, Whole FORM; class="container" or class="container-fluid"
$html .= '<div ' . Support::doAttribute('class', $this->formSpec[F_CLASS], TRUE) . '>'; // main <div class=...> around everything, Whole FORM; class="container" or class="container-fluid"
$title = Support::wrapTag('<div class="hidden-xs col-sm-6 col-md-8">', Support::wrapTag('<h3>', $this->formSpec['title']));
$button = Support::wrapTag('<div class="col-xs-12 col-sm-6 col-md-4">', $this->buildButtons());
......
......@@ -70,7 +70,7 @@ class BuildFormTable extends AbstractBuildForm {
public function head() {
$html = '';
$html .= '<div ' . Support::doAttribute('class', $this->formSpec['class'], TRUE) . '>'; // main <div class=...> around everything
$html .= '<div ' . Support::doAttribute('class', $this->formSpec[F_CLASS], TRUE) . '>'; // main <div class=...> around everything
// Logged in BE User will see a FormEdit Link
$sipParamString = OnArray::toString($this->store->getStore(STORE_SIP), ':', ', ', "'");
......
......@@ -297,6 +297,7 @@ const SYSTEM_SHOW_DEBUG_INFO = 'SHOW_DEBUG_INFO';
const SYSTEM_CSS_LINK_CLASS_INTERNAL = 'CSS_LINK_CLASS_INTERNAL';
const SYSTEM_CSS_LINK_CLASS_EXTERNAL = 'CSS_LINK_CLASS_EXTERNAL';
const SYSTEM_CSS_CLASS_QFQ_CONTAINER = 'CSS_CLASS_QFQ_CONTAINER';
const SYSTEM_CSS_CLASS_QFQ_FORM = 'CSS_CLASS_QFQ_FORM';
const SYSTEM_CSS_CLASS_QFQ_FORM_PILL = 'CSS_CLASS_QFQ_FORM_PILL';
const SYSTEM_CSS_CLASS_QFQ_FORM_BODY = 'CSS_CLASS_QFQ_FORM_BODY';
......@@ -464,6 +465,7 @@ const F_FINAL_DELETE_FORM = 'finalDeleteForm';
const F_SUBMIT_BUTTON_TEXT = 'submitButtonText';
const F_CLASS = 'class';
const F_CLASS_PILL = 'classPill';
const F_CLASS_BODY = 'classBody';
......
......@@ -387,7 +387,8 @@ class QuickFormQuery {
$formSpec = $this->eval->parseArray($form);
HelperFormElement::explodeParameter($formSpec);
$formSpec = $this->setFormDefault($formSpec);
$formSpec = $this->syncSystemFormConfig($formSpec);
$formSpec = $this->initForm($formSpec);
// Set F_FINAL_DELETE_FORM
$formSpec[F_FINAL_DELETE_FORM] = ($formSpec[F_EXTRA_DELETE_FORM] != '') ? $formSpec[F_EXTRA_DELETE_FORM] : $formSpec[F_NAME];
......@@ -505,56 +506,62 @@ class QuickFormQuery {
}
/**
* If not already defined, set various defaults on the form.
* The named $keys will be synced between STORE_SYSTEM and $formSpec (both directions).
* The per form definition has precedence over STORE_SYSTEM.
* STORE_SYSTEM if filled with the default values (config.qfq.ini or if note exist than QFQ hardcoded)
* Copying the 'Form' definition back to the system store helps to access the values
* by '{{ ...:Y}}' (system store). E.g. the value of bs-*-columns might be displayed as placeholder in the
* corresponding inputfield.
*
* @param array $formSpec
* @return array
*/
private function setFormDefault(array $formSpec) {
# Set defaults:
Support::setIfNotSet($formSpec, 'class', '');
$value = $this->store->getVar(F_BS_LABEL_COLUMNS, STORE_SYSTEM);
Support::setIfNotSet($formSpec, F_BS_LABEL_COLUMNS, $value, '');
$value = $this->store->getVar(F_BS_INPUT_COLUMNS, STORE_SYSTEM);
Support::setIfNotSet($formSpec, F_BS_INPUT_COLUMNS, $value, '');
$value = $this->store->getVar(F_BS_NOTE_COLUMNS, STORE_SYSTEM);
Support::setIfNotSet($formSpec, F_BS_NOTE_COLUMNS, $value, '');
Support::setIfNotSet($formSpec, F_SUBMIT_BUTTON_TEXT, '');
Support::setIfNotSet($formSpec, F_EXTRA_DELETE_FORM, '');
// Take default from config.ini
$value = $this->store->getVar(SYSTEM_FORM_DATA_PATTERN_ERROR, STORE_SYSTEM);
Support::setIfNotSet($formSpec, F_FE_DATA_PATTERN_ERROR, ($value !== false) ? $value : '');
// Take default from config.ini
$value = $this->store->getVar(SYSTEM_FORM_DATA_REQUIRED_ERROR, STORE_SYSTEM);
Support::setIfNotSet($formSpec, F_FE_DATA_REQUIRED_ERROR, ($value !== false) ? $value : '');
private function syncSystemFormConfig(array $formSpec) {
$keys = [F_BS_LABEL_COLUMNS,
F_BS_INPUT_COLUMNS,
F_BS_NOTE_COLUMNS,
F_FE_DATA_PATTERN_ERROR,
F_FE_DATA_REQUIRED_ERROR,
F_FE_DATA_MATCH_ERROR,
F_FE_DATA_ERROR,
F_CLASS,
F_CLASS_PILL,
F_CLASS_BODY,
];
// By definition: existing vars which are empty, means: EMPTY - do not use any default!
// But: if these variables are table columns, they always exist. For those: empty value means 'not set' - unset those.
foreach ([F_BS_LABEL_COLUMNS, F_BS_INPUT_COLUMNS, F_BS_NOTE_COLUMNS] as $key) {
if ($formSpec[$key] == '') {
unset ($formSpec[$key]);
}
}
// Take default from config.ini
$value = $this->store->getVar(SYSTEM_FORM_DATA_MATCH_ERROR, STORE_SYSTEM);
Support::setIfNotSet($formSpec, F_FE_DATA_MATCH_ERROR, ($value !== false) ? $value : '');
foreach ($keys as $key) {
// Take default from config.ini
$value = $this->store->getVar(SYSTEM_FORM_DATA_ERROR, STORE_SYSTEM);
Support::setIfNotSet($formSpec, F_FE_DATA_ERROR, ($value !== false) ? $value : '');
if (isset($formSpec[$key])) {
$this->store->setVar($key, $formSpec[$key], STORE_SYSTEM);
} else {
// if not found set ''
$formSpec[$key] = $this->store->getVar($key, STORE_SYSTEM . STORE_EMPTY);
}
}
// Take default from config.ini
$class = $this->store->getVar(SYSTEM_CSS_CLASS_QFQ_FORM_PILL, STORE_SYSTEM);
$class = $class ? $class : 'qfq-color-grey-1';
Support::setIfNotSet($formSpec, F_CLASS_PILL, $class);
return $formSpec;
}
// Take default from config.ini
$class = $this->store->getVar(SYSTEM_CSS_CLASS_QFQ_FORM_BODY, STORE_SYSTEM);
$class = $class ? $class : 'qfq-color-grey-2';
Support::setIfNotSet($formSpec, F_CLASS_BODY, $class);
/**
* Set form parameter which are expected to exist.
*
* @param array $config
* @return array
*/
private function initForm(array $config) {
Support::setIfNotSet($config, F_EXTRA_DELETE_FORM, '');
Support::setIfNotSet($config, F_SUBMIT_BUTTON_TEXT, '');
return $formSpec;
return $config;
}
/**
......
......@@ -166,7 +166,7 @@ class Store {
}
/**
* Fills the system store.
* Fill the system store by reading config.qfq.ini. Also setup config defaults.
*
* @throws CodeException
* @throws qfq\UserFormException
......@@ -197,26 +197,14 @@ class Store {
Support::setIfNotSet($config, F_BS_LABEL_COLUMNS, '3');
Support::setIfNotSet($config, F_BS_INPUT_COLUMNS, '6');
Support::setIfNotSet($config, F_BS_NOTE_COLUMNS, '3');
Support::setIfNotSet($config, F_CLASS_PILL, 'qfq-color-grey-1');
Support::setIfNotSet($config, F_CLASS_BODY, 'qfq-color-grey-2');
// Adjust config
if ($config[SYSTEM_SHOW_DEBUG_INFO] === 'auto') {
$config[SYSTEM_SHOW_DEBUG_INFO] = (isset($GLOBALS["TSFE"]->beUserLogin) && $GLOBALS["TSFE"]->beUserLogin === true) ? 'yes' : 'no';
}
$config = self::doSystemPath($config);
$config = self::adjustConfig($config);
// make SQL PATH absolute. This is necessary to work in different directories correctly.
if (isset($config[SYSTEM_SQL_LOG]) && $config[SYSTEM_SQL_LOG][0] !== '/') {
$config[SYSTEM_SQL_LOG] = $config[SYSTEM_PATH_EXT] . '/' . $config[SYSTEM_SQL_LOG];
}
// Check mandatory config vars.
$names = array('DB_USER', 'DB_SERVER', 'DB_PASSWORD', 'DB_NAME', 'SQL_LOG', 'SQL_LOG_MODE');
foreach ($names as $name) {
if (!isset($config[$name])) {
throw new qfq\UserFormException ("Missing configuration in `config.ini`: $name", ERROR_MISSING_CONFIG_INI_VALUE);
}
}
self::checkMandatoryParameter($config);
self::setVarArray($config, STORE_SYSTEM, true);
}
......@@ -235,6 +223,13 @@ class Store {
[SYSTEM_FORM_BS_LABEL_COLUMNS, F_BS_LABEL_COLUMNS],
[SYSTEM_FORM_BS_INPUT_COLUMNS, F_BS_INPUT_COLUMNS],
[SYSTEM_FORM_BS_NOTE_COLUMNS, F_BS_NOTE_COLUMNS],
[SYSTEM_FORM_DATA_PATTERN_ERROR, F_FE_DATA_PATTERN_ERROR],
[SYSTEM_FORM_DATA_REQUIRED_ERROR, F_FE_DATA_REQUIRED_ERROR],
[SYSTEM_FORM_DATA_MATCH_ERROR, F_FE_DATA_MATCH_ERROR],
[SYSTEM_FORM_DATA_ERROR, F_FE_DATA_ERROR],
[SYSTEM_CSS_CLASS_QFQ_FORM, F_CLASS],
[SYSTEM_CSS_CLASS_QFQ_FORM_PILL, F_CLASS_PILL],
[SYSTEM_CSS_CLASS_QFQ_FORM_BODY, F_CLASS_BODY],
];
foreach ($setting as $row) {
......@@ -253,6 +248,7 @@ class Store {
}
/**
* QFQ might be called via Typo3 (index.php) or directly via AJAX (directory: api). The
* @param array $config
* @return array
*/
......@@ -281,9 +277,46 @@ class Store {
$config[SYSTEM_PATH_EXT] = getcwd();
}
}
return $config;
}
/**
* Depending on some configuration value, update corresponding values.
*
* @param array $config
* @return array
*/
private static function adjustConfig(array $config) {
// Adjust config
if ($config[SYSTEM_SHOW_DEBUG_INFO] === 'auto') {
$config[SYSTEM_SHOW_DEBUG_INFO] = (isset($GLOBALS["TSFE"]->beUserLogin) && $GLOBALS["TSFE"]->beUserLogin === true) ? 'yes' : 'no';
}
// make SQL PATH absolute. This is necessary to work in different directories correctly.
if (isset($config[SYSTEM_SQL_LOG]) && $config[SYSTEM_SQL_LOG][0] !== '/') {
$config[SYSTEM_SQL_LOG] = $config[SYSTEM_PATH_EXT] . '/' . $config[SYSTEM_SQL_LOG];
}
return $config;
}
/**
* Iterate over all Parameter which have to exist in the config. Throw an array if any is missing.
*
* @param array $config
* @throws UserFormException
*/
private static function checkMandatoryParameter(array $config) {
// Check mandatory config vars.
$names = array('DB_USER', 'DB_SERVER', 'DB_PASSWORD', 'DB_NAME', 'SQL_LOG', 'SQL_LOG_MODE');
foreach ($names as $name) {
if (!isset($config[$name])) {
throw new qfq\UserFormException ("Missing configuration in `config.ini`: $name", ERROR_MISSING_CONFIG_INI_VALUE);
}
}
}
/**
* Set or overwrite a complete store.
*
......@@ -645,6 +678,7 @@ class Store {
/**
* Return an array with non system SIP parameter. Take the whole STORE_SIP and search for non system parameter.
*
* @return array
* @throws UserFormException
* @throws \qfq\CodeException
......
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