Added feature #5610: Extend TCEFORM_confObj on Page TSconfig by property keepItems
authorOliver Hader <oliver.hader@typo3.org>
Tue, 30 Dec 2008 11:12:29 +0000 (11:12 +0000)
committerOliver Hader <oliver.hader@typo3.org>
Tue, 30 Dec 2008 11:12:29 +0000 (11:12 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@4630 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_div.php
t3lib/class.t3lib_tceforms.php
t3lib/class.t3lib_tceforms_inline.php
typo3/sysext/cms/layout/db_new_content_el.php

index f0c4983..d1cd128 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-12-30  Oliver Hader  <oliver@typo3.org>
+
+       * Added feature #5610: Extend TCEFORM_confObj on Page TSconfig by property keepItems
+
 2008-12-29  Ernesto Baschny  <ernst@cron-it.de>
 
        * Fixed bug #8746: Date/time field problem with timezone shifting when using the "+NN", "d" or "d+NN" shortcuts
index abcff08..a321765 100755 (executable)
@@ -1697,6 +1697,53 @@ final class t3lib_div {
        }
 
        /**
+        * Filters an array to reduce its elements to match the condition.
+        * The values in $keepItems can be optionally evaluated by a custom callback function.
+        *
+        * Example (arguments used to call this function):
+        * $array = array(
+        *              array('aa' => array('first', 'second'),
+        *              array('bb' => array('third', 'fourth'),
+        *              array('cc' => array('fifth', 'sixth'),
+        * );
+        * $keepItems = array('third');
+        * $getValueFunc = create_function('$value', 'return $value[0];');
+        *
+        * Returns:
+        * array(
+        *              array('bb' => array('third', 'fourth'),
+        * )
+        *
+        * @param       array           $array: The initial array to be filtered/reduced
+        * @param       mixed           $keepItems: The items which are allowed/kept in the array - accepts array or csv string
+        * @param       string          $getValueFunc: (optional) Unique function name set by create_function() used to get the value to keep
+        * @return      array           The filtered/reduced array with the kept items
+        */
+       public function keepItemsInArray(array $array, $keepItems, $getValueFunc=null) {
+               if ($array) {
+                               // Convert strings to arrays:
+                       if (is_string($keepItems)) {
+                               $keepItems = t3lib_div::trimExplode(',', $keepItems);
+                       }
+                               // create_function() returns a string:
+                       if (!is_string($getValueFunc)) {
+                               $getValueFunc = null; 
+                       }
+                               // Do the filtering:
+                       if (is_array($keepItems) && count($keepItems)) {
+                               foreach ($array as $key => $value) {
+                                               // Get the value to compare by using the callback function:
+                                       $keepValue = (isset($getValueFunc) ? $getValueFunc($value) : $value);
+                                       if (!in_array($keepValue, $keepItems)) {
+                                               unset($array[$key]);
+                                       }
+                               }
+                       }
+               }
+               return $array;
+       }
+
+       /**
         * Implodes a multidim-array into GET-parameters (eg. &param[key][key2]=value2&param[key][key3]=value3)
         * Usage: 24
         *
index 82c93c2..d633e7c 100755 (executable)
@@ -1425,9 +1425,21 @@ class t3lib_TCEforms     {
                $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
 
                        // Getting the selector box items from the system
-               $selItems = $this->addSelectOptionsToItemArray($this->initItemArray($PA['fieldConf']),$PA['fieldConf'],$this->setTSconfig($table,$row),$field);
-               $selItems = $this->addItems($selItems,$PA['fieldTSConfig']['addItems.']);
-               if ($config['itemsProcFunc']) $selItems = $this->procItems($selItems,$PA['fieldTSConfig']['itemsProcFunc.'],$config,$table,$row,$field);
+               $selItems = $this->addSelectOptionsToItemArray(
+                       $this->initItemArray($PA['fieldConf']),
+                       $PA['fieldConf'],
+                       $this->setTSconfig($table, $row),
+                       $field
+               );
+                       // Possibly filter some items:
+               $keepItemsFunc = create_function('$value', 'return $value[1];');
+               $selItems = t3lib_div::keepItemsInArray($selItems, $PA['fieldTSConfig']['keepItems'], $keepItemsFunc);
+                       // Possibly add some items:
+               $selItems = $this->addItems($selItems, $PA['fieldTSConfig']['addItems.']);
+                       // Process items by a user function:
+               if (isset($config['itemsProcFunc']) && $config['itemsProcFunc']) {
+                       $selItems = $this->procItems($selItems, $PA['fieldTSConfig']['itemsProcFunc.'], $config, $table, $row, $field);
+               }
 
                        // Possibly remove some items:
                $removeItems = t3lib_div::trimExplode(',',$PA['fieldTSConfig']['removeItems'],1);
@@ -1939,8 +1951,14 @@ class t3lib_TCEforms     {
                        // Get "removeItems":
                $removeItems = t3lib_div::trimExplode(',',$PA['fieldTSConfig']['removeItems'],1);
 
+                       // Get the array with selected items:
+               $itemArray = t3lib_div::trimExplode(',', $PA['itemFormElValue'], 1);
+
+                       // Possibly filter some items:
+               $keepItemsFunc = create_function('$value', '$parts=explode(\'|\',$value,2); return rawurldecode($parts[0]);');
+               $itemArray = t3lib_div::keepItemsInArray($itemArray, $PA['fieldTSConfig']['keepItems'], $keepItemsFunc);
+
                        // Perform modification of the selected items array:
-               $itemArray = t3lib_div::trimExplode(',',$PA['itemFormElValue'],1);
                foreach($itemArray as $tk => $tv) {
                        $tvP = explode('|',$tv,2);
                        $evalValue = rawurldecode($tvP[0]);
index c88a831..c23f285 100755 (executable)
@@ -1482,8 +1482,20 @@ class t3lib_TCEforms_inline {
 
                if ($foreignConfig['type'] == 'select') {
                                // Getting the selector box items from the system
-                       $selItems = $this->fObj->addSelectOptionsToItemArray($this->fObj->initItemArray($PA['fieldConf']),$PA['fieldConf'],$this->fObj->setTSconfig($table,$row),$field);
-                       if ($config['itemsProcFunc']) $selItems = $this->fObj->procItems($selItems,$PA['fieldTSConfig']['itemsProcFunc.'],$config,$table,$row,$field);
+                       $selItems = $this->fObj->addSelectOptionsToItemArray(
+                               $this->fObj->initItemArray($PA['fieldConf']),
+                               $PA['fieldConf'],
+                               $this->fObj->setTSconfig($table, $row),
+                               $field
+                       );
+                               // Possibly filter some items:
+                       $keepItemsFunc = create_function('$value', 'return $value[1];');
+                       $selItems = t3lib_div::keepItemsInArray($selItems, $PA['fieldTSConfig']['keepItems'], $keepItemsFunc);
+                               // Possibly add some items:
+                       $selItems = $this->addItems($selItems, $PA['fieldTSConfig']['addItems.']);
+                       if (isset($config['itemsProcFunc']) && $config['itemsProcFunc']) {
+                               $selItems = $this->fObj->procItems($selItems, $PA['fieldTSConfig']['itemsProcFunc.'], $config, $table, $row, $field);
+                       }
 
                                // Possibly remove some items:
                        $removeItems = t3lib_div::trimExplode(',',$PA['fieldTSConfig']['removeItems'],1);
index 466c038..46ff3ee 100644 (file)
@@ -576,9 +576,10 @@ Contact me: | tv=check | 1
                t3lib_div::loadTCA('tt_content');
 
                        // Get TCEFORM from TSconfig of current page
-               $row = array('pid'=>$this->id);
-               $TCEFORM_TSconfig = t3lib_BEfunc::getTCEFORM_TSconfig('tt_content',$row);
-               $removeItems = t3lib_div::trimExplode(',',$TCEFORM_TSconfig['CType']['removeItems'],1);
+               $row = array('pid' => $this->id);
+               $TCEFORM_TSconfig = t3lib_BEfunc::getTCEFORM_TSconfig('tt_content', $row);
+               $removeItems = t3lib_div::trimExplode(',', $TCEFORM_TSconfig['CType']['removeItems'], 1);
+               $keepItems = t3lib_div::trimExplode(',', $TCEFORM_TSconfig['CType']['keepItems'], 1);
 
                $headersUsed = Array();
                        // Traverse wizard items:
@@ -604,9 +605,10 @@ Contact me: | tv=check | 1
                                        if (is_array($TCA['tt_content']['columns'][$fN]))       {
                                                        // Get information about if the field value is OK:
                                                $config = &$TCA['tt_content']['columns'][$fN]['config'];
-                                               $authModeDeny = $config['type']=='select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode('tt_content',$fN,$fV,$config['authMode']);
+                                               $authModeDeny = ($config['type']=='select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode('tt_content', $fN, $fV, $config['authMode']));
+                                               $isNotInKeepItems = (count($keepItems) && !in_array($fV, $keepItems));
 
-                                               if ($authModeDeny || ($fN=='CType' && in_array($fV,$removeItems)))      {
+                                               if ($authModeDeny || ($fN=='CType' && in_array($fV,$removeItems)) || $isNotInKeepItems) {
                                                                // Remove element all together:
                                                        unset($wizardItems[$key]);
                                                        break;