Fixed feature request: TCEforms/IRRE - Allow TSconfig to override TCA field configuration
authorOliver Hader <oliver.hader@typo3.org>
Sat, 3 Feb 2007 16:57:47 +0000 (16:57 +0000)
committerOliver Hader <oliver.hader@typo3.org>
Sat, 3 Feb 2007 16:57:47 +0000 (16:57 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@1967 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_div.php
t3lib/class.t3lib_tceforms.php
t3lib/class.t3lib_tceforms_inline.php

index 39e7b69..d1c9331 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
+2007-02-03  Oliver Hader  <oh@inpublica.de>
 
-2007-02-30  Martin Kutschker  <martin.t.kutschker@blackbox.net>
+       * Fixed feature request: TCEforms/IRRE - Allow TSconfig to override TCA field configuration
+
+2007-02-02  Martin Kutschker  <martin.t.kutschker@blackbox.net>
 
        * Changed class.t3lib_cipboard.php and class.db_list_extra.inc to use new mod.php?M=xMOD_tximpexp (instead old impexp/app/index.php)
 
index 3346d1f..2d05927 100755 (executable)
@@ -1707,6 +1707,28 @@ class t3lib_div {
                return $str;
        }
 
+       /**
+        * Removes dots "." from end of a key identifier of TypoScript styled array.
+        * array('key.' => array('property.' => 'value')) --> array('key' => array('property' => 'value'))
+        *
+        * @param       array   $ts: TypoScript configuration array
+        * @return      array   TypoScript configuration array without dots and the end of all keys 
+        */
+       function removeDotsFromTS($ts) {
+               $out = array();
+               if (is_array($ts)) {
+                       foreach ($ts as $key => $value) {
+                               if (is_array($value)) {
+                                       $key = rtrim($key, '.');
+                                       $out[$key] = t3lib_div::removeDotsFromTS($value);
+                               } else {
+                                       $out[$key] = $value;
+                               }
+                       }
+               }
+               return $out;
+       }
+
 
 
 
index cdbd37d..1d9a960 100755 (executable)
@@ -247,6 +247,7 @@ class t3lib_TCEforms        {
        var $prependCmdFieldNames = 'cmd';                      // The string to prepend commands for tcemain::process_cmdmap with.
        var $prependFormFieldNames_file = 'data_files';         // The string to prepend FILE form field names with.
        var $formName = 'editform';                                     // The name attribute of the form.
+       var $allowOverrideMatrix = array();                     // Whitelist that allows TCA field configuration to be overridden by TSconfig, @see overrideFieldConf()
 
 
 
@@ -331,6 +332,13 @@ class t3lib_TCEforms       {
                $this->defColorScheme = $this->colorScheme;
                $this->defClassScheme = $this->classScheme;
 
+                       // Define whitelist that allows TCA field configuration to be overridden by TSconfig, @see overrideFieldConf():
+               $this->allowOverrideMatrix = array(
+                       'select' => array('minitems', 'maxitems', 'size'),
+                       'group' => array('minitems', 'maxitems', 'size'),
+                       'inline' => array('minitems', 'maxitems', 'size', 'foreign_selector', 'foreign_unique', 'appearance'),
+               );
+
                $this->inline = t3lib_div::makeInstance('t3lib_TCEforms_inline');
        }
 
@@ -786,6 +794,8 @@ class t3lib_TCEforms        {
 
                                // If the field is NOT disabled from TSconfig (which it could have been) then render it
                        if (!$PA['fieldTSConfig']['disabled'])  {
+                                       // Override fieldConf by fieldTSconfig:
+                               $PA['fieldConf']['config'] = $this->overrideFieldConf($PA['fieldConf']['config'], $PA['fieldTSConfig']);
 
                                        // Init variables:
                                $PA['itemFormElName']=$this->prependFormFieldNames.'['.$table.']['.$row['uid'].']['.$field.']';         // Form field name
@@ -2786,6 +2796,37 @@ class t3lib_TCEforms     {
        }
 
        /**
+        * Overrides the TCA field configuration by TSconfig settings.
+        * 
+        * Example TSconfig: TCEform.<table>.<field>.config.appearance.useSortable = 1
+        * This overrides the setting in $TCA[<table>]['columns'][<field>]['config']['appearance']['useSortable'].
+        *
+        * @param       array           $fieldConfig: TCA field configuration
+        * @param       array           $TSconfig: TSconfig
+        * @return      array           Changed TCA field configuration
+        */
+       function overrideFieldConf($fieldConfig, $TSconfig) {
+               if (is_array($TSconfig)) {
+                       $TSconfig = t3lib_div::removeDotsFromTS($TSconfig);
+                       $type = $fieldConfig['type'];
+                       if (is_array($this->allowOverrideMatrix[$type])) {
+                                       // Check if the keys in TSconfig['config'] are allowed to override TCA field config:                    
+                               foreach (array_keys($TSconfig['config']) as $key) {
+                                       if (!in_array($key, $this->allowOverrideMatrix[$type], true)) {
+                                               unset($TSconfig['config'][$key]);
+                                       }
+                               }
+                                       // Override TCA field config by remaining TSconfig['config']:
+                               if (count($TSconfig['config'])) {
+                                       $fieldConfig = array_merge($fieldConfig, $TSconfig['config']);
+                               }
+                       }
+               }
+
+               return $fieldConfig;
+       }
+
+       /**
         * Returns the "special" configuration (from the "types" "showitem" list) for a fieldname based on input table/record
         * (Not used anywhere...?)
         *
index 83a5baf..0c7da54 100755 (executable)
@@ -1125,6 +1125,16 @@ class t3lib_TCEforms_inline {
                                        if ($loadConfig) {
                                                t3lib_div::loadTCA($unstable['table']);
                                                $unstable['config'] = $GLOBALS['TCA'][$unstable['table']]['columns'][$unstable['field']]['config'];
+                                                       // Fetch TSconfig:
+                                               $TSconfig = $this->fObj->setTSconfig(
+                                                       $unstable['table'],
+                                                       array('uid' => $unstable['uid'], 'pid' => $this->inlineFirstPid),
+                                                       $unstable['field']
+                                               );
+                                                       // Override TCA field config by TSconfig:
+                                               if (!$TSconfig['disabled']) {
+                                                       $unstable['config'] = $this->fObj->overrideFieldConf($unstable['config'], $TSconfig);
+                                               }
                                        }
                                        $this->inlineStructure['stable'][] = $unstable;
                                        $unstable = array();