[BUGFIX] tcaTree: make own record unselectable
authorSteffen Ritter <info@rs-websystems.de>
Wed, 2 Mar 2011 14:50:40 +0000 (15:50 +0100)
committerSteffen Ritter <info@rs-websystems.de>
Fri, 8 Jul 2011 12:04:30 +0000 (14:04 +0200)
Relations to an own record is not useful. You could exclude is via tca "andWhere"
This is not nice, because you wouldn't  see the whole tree.
Just make the own record unselectable.

Change-Id: I7c0cc969586c90ea3861754605d95b072eedad88
Resolves: #24324
Releases: 4.6, 4.5
Reviewed-on: http://review.typo3.org/976
Reviewed-by: Oliver Hader
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
Reviewed-by: Stefan Neufeind
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
t3lib/tree/tca/class.t3lib_tree_tca_abstracttcatreedataprovider.php
t3lib/tree/tca/class.t3lib_tree_tca_databasetreedataprovider.php
t3lib/tree/tca/class.t3lib_tree_tca_dataproviderfactory.php

index 71824dd..013e8c2 100644 (file)
@@ -72,6 +72,11 @@ abstract class t3lib_tree_Tca_AbstractTcaTreeDataProvider extends t3lib_tree_Abs
        protected $itemWhiteList = array();
 
        /**
+        * Contains all ids which are not allowed to be selected
+        */
+       protected $itemUnselectableList = array();
+
+       /**
         * Sets the id of the tree
         *
         * @param string $treeId
@@ -223,6 +228,25 @@ abstract class t3lib_tree_Tca_AbstractTcaTreeDataProvider extends t3lib_tree_Abs
        public function getItemWhiteList() {
                return $this->itemWhiteList;
        }
+
+       /**
+        * Setter for $itemUnselectableList
+        *
+        * @param array $itemUnselectableList
+        * @return void
+        */
+       public function setItemUnselectableList(array $itemUnselectableList) {
+               $this->itemUnselectableList = $itemUnselectableList;
+       }
+
+       /**
+        * Getter for $itemUnselectableList
+        *
+        * @return array
+        */
+       public function getItemUnselectableList() {
+               return $this->itemUnselectableList;
+       }
 }
 
 ?>
\ No newline at end of file
index cdb2625..b70dc93 100644 (file)
@@ -260,7 +260,10 @@ class t3lib_tree_Tca_DatabaseTreeDataProvider extends t3lib_tree_Tca_AbstractTca
                }
                $node->setId($basicNode->getId());
 
-               $node->setSelectable(!t3lib_div::inList($this->getNonSelectableLevelList(), $level));
+               $node->setSelectable(
+                       !t3lib_div::inList($this->getNonSelectableLevelList(), $level)
+                       && !in_array($basicNode->getId(), $this->getItemUnselectableList())
+               );
                $node->setSortValue($this->nodeSortValues[$basicNode->getId()]);
 
                $node->setIcon(t3lib_iconWorks::mapRecordTypeToSpriteIconClass($this->tableName, $row));
index 6cb56aa..3e05b54 100644 (file)
@@ -50,6 +50,8 @@ class t3lib_tree_Tca_DataProviderFactory {
                }
 
                if ($tcaConfiguration['internal_type'] == 'db') {
+                       $unselectableUids = array();
+
                        /**
                         * @var $dataProvider t3lib_tree_Tca_DatabaseTreeDataProvider
                         */
@@ -59,6 +61,10 @@ class t3lib_tree_Tca_DataProviderFactory {
                                $tableName = $tcaConfiguration['foreign_table'];
                                $dataProvider->setTableName($tableName);
 
+                               if ($tableName == $table) {
+                                       $unselectableUids[] = $currentValue['uid'];
+                               }
+
                                t3lib_div::loadTCA($tableName);
                        } else {
                                throw new InvalidArgumentException(
@@ -107,6 +113,8 @@ class t3lib_tree_Tca_DataProviderFactory {
                                                '1288215889'
                                        );
                                }
+
+                               $dataProvider->setItemUnselectableList($unselectableUids);
                        } else {
                                throw new InvalidArgumentException(
                                        'TCA Tree configuration is invalid: "treeConfig" array is missing',