[BUGFIX] Drag&Drop inside the root page of the pagetree isn't possible
authorStefan Galinski <stefan.galinski@gmail.com>
Thu, 28 Jun 2012 08:25:05 +0000 (10:25 +0200)
committerErnesto Baschny <ernst@cron-it.de>
Thu, 12 Jul 2012 07:26:36 +0000 (09:26 +0200)
In case there is no page (except the root page) within TYPO3, you can't
use the drag and drop functionality in the page tree to create the first
page.

Change-Id: I4f4aed78916f1ab0ebf9bbc1baad2b2743e9d1b2
Fixes: #24626
Releases: 6.0, 4.7, 4.6, 4.5
Reviewed-on: http://review.typo3.org/12437
Reviewed-by: Christian Kuhn
Reviewed-by: Ernesto Baschny
Tested-by: Ernesto Baschny
t3lib/js/extjs/components/pagetree/javascript/tree.js
t3lib/tree/pagetree/class.t3lib_tree_pagetree_dataprovider.php
tests/t3lib/tree/pagetree/t3lib_tree_pagetree_dataproviderTest.php [new file with mode: 0644]

index e071467..a3cb674 100644 (file)
@@ -403,6 +403,7 @@ TYPO3.Components.PageTree.Tree = Ext.extend(Ext.tree.TreePanel, {
                        // init proxy element
                this.on('startdrag', this.initDd, this);
                this.on('enddrag', this.stopDd, this);
+               this.on('nodedragover', this.nodeDragOver, this);
 
                        // node is moved
                this.on('movenode', this.moveNode, this);
@@ -500,6 +501,17 @@ TYPO3.Components.PageTree.Tree = Ext.extend(Ext.tree.TreePanel, {
        },
 
        /**
+        * Cancels the drop possibility for the position above and below a mount page
+        *
+        * @param {Object} event
+        * @return {void}
+        */
+       nodeDragOver: function(event) {
+               var isMountPage = (event.target.attributes.realId == 0 || event.target.attributes.nodeData.isMountPoint);
+               return !((event.point === 'above' || event.point === 'below') && isMountPage);
+       },
+
+       /**
         * Creates a Fake Node
         *
         * This must be done to prevent the calling of the moveNode event.
index 0e769c5..97fb639 100644 (file)
@@ -111,12 +111,16 @@ class t3lib_tree_pagetree_DataProvider extends t3lib_tree_AbstractDataProvider {
                                continue;
                        }
 
+                               // must be calculated above getRecordWSOL, because the information is lost otherwise
+                       $isMountPoint = ($subpage['isMountPoint'] === TRUE);
+
                        $subpage = t3lib_befunc::getRecordWSOL('pages', $subpage['uid'], '*', '', TRUE, TRUE);
                        if (!$subpage) {
                                continue;
                        }
 
                        $subNode = t3lib_tree_pagetree_Commands::getNewNode($subpage, $mountPoint);
+                       $subNode->setIsMountPoint($isMountPoint);
                        if ($this->nodeCounter < $this->nodeLimit) {
                                $childNodes = $this->getNodes($subNode, $mountPoint, $level + 1);
                                $subNode->setChildNodes($childNodes);
@@ -297,7 +301,6 @@ class t3lib_tree_pagetree_DataProvider extends t3lib_tree_AbstractDataProvider {
 
                        $subNode->setIsMountPoint(TRUE);
                        $subNode->setDraggable(FALSE);
-                       $subNode->setIsDropTarget(FALSE);
 
                        if ($searchFilter === '') {
                                $childNodes = $this->getNodes($subNode, $mountPoint);
@@ -391,4 +394,4 @@ if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLA
        include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/tree/pagetree/class.t3lib_tree_pagetree_dataprovider.php']);
 }
 
-?>
+?>
\ No newline at end of file
diff --git a/tests/t3lib/tree/pagetree/t3lib_tree_pagetree_dataproviderTest.php b/tests/t3lib/tree/pagetree/t3lib_tree_pagetree_dataproviderTest.php
new file mode 100644 (file)
index 0000000..201f0dd
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Stefan Galinski <stefan.galinski@gmail.com>
+*  All rights reserved
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Testcase for class t3lib_tree_pagetree_DataProvider.
+ *
+ * @author Stefan Galinski <stefan.galinski@gmail.com>
+ * @package TYPO3
+ * @subpackage t3lib
+ */
+class t3lib_tree_pagetree_DataProviderTest extends tx_phpunit_testcase {
+       /**
+        * @var PHPUnit_Framework_MockObject_MockObject|t3lib_tree_pagetree_DataProvider
+        */
+       protected $fixture = NULL;
+
+       /**
+        * @var array
+        */
+       protected $backupGlobalVariables = array();
+
+       public function setUp() {
+               $this->backupGlobalVariables['TYPO3_CONF_VARS'] = $GLOBALS['TYPO3_CONF_VARS'];
+               $GLOBALS['TYPO3_CONF_VARS']['BE']['pageTree']['preloadLimit'] = 0;
+       }
+
+       public function tearDown() {
+               unset($this->fixture);
+
+               foreach ($this->backupGlobalVariables as $name => $value) {
+                       $GLOBALS[$name] = $value;
+               }
+       }
+
+       /**
+        * @test
+        */
+       public function getNodesSetsIsMountPointField() {
+               $subpages = array(
+                       array(
+                               'uid' => 1,
+                               'isMountPoint' => FALSE,
+                       ),
+                       array(
+                               'uid' => 2,
+                               'isMountPoint' => TRUE,
+                       ),
+                       array(
+                               'uid' => 3,
+                       ),
+               );
+
+               foreach ($subpages as $subpage) {
+                       if (!t3lib_BEfunc::getRecordWSOL('pages', $subpage['uid'])) {
+                               $this->markTestSkipped('getNodesSetsIsMountPointField test only available if pages with uid 1, 2 and 3 exist');
+                       }
+               }
+
+               $this->fixture = $this->getMock('t3lib_tree_pagetree_DataProvider', array('getSubpages'));
+               $this->fixture->expects($this->once())->method('getSubpages')
+                       ->will($this->returnValue($subpages));
+
+               $node = new t3lib_tree_Node();
+               $node->setId(12);
+
+               $nodeCollection = $this->fixture->getNodes($node);
+
+               /** @var $node t3lib_tree_pagetree_Node */
+               $isMountPointResult = array();
+               foreach ($nodeCollection as $node) {
+                       $isMountPointResult[] = $node->isMountPoint();
+               }
+               $this->assertSame(array(FALSE, TRUE, FALSE), $isMountPointResult);
+       }
+}
+
+?>
\ No newline at end of file