[BUGFIX] Movements pollute colPos value of content elements
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / View / PageLayoutView.php
index 2a1e602..5d49fc8 100644 (file)
@@ -472,6 +472,7 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
                                        ';
                                        $editUidList = '';
                                        $rowArr = $contentRecordsPerColumn[$key];
+                                       $this->generateTtContentDataArray($rowArr);
                                        foreach ((array) $rowArr as $rKey => $row) {
                                                if ($this->tt_contentConfig['languageMode']) {
                                                        $languageColumn[$key][$lP] = $head[$key] . $content[$key];
@@ -751,6 +752,7 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
                                foreach ($cList as $counter => $key) {
                                        $c = 0;
                                        $rowArr = $contentRecordsPerColumn[$key];
+                                       $this->generateTtContentDataArray($rowArr);
                                        $numberOfContentElementsInColumn = count($rowArr);
                                        $rowOut = '';
                                        // If it turns out that there are not content elements in the column, then display a big button which links directly to the wizard script:
@@ -1809,10 +1811,6 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
         * @todo Define visibility
         */
        public function getResult($result, $table = 'tt_content') {
-               // Initialize:
-               $recs = array();
-               $nextTree = $this->nextThree;
-               $c = 0;
                $output = array();
                // Traverse the result:
                while ($row = $this->getDatabase()->sql_fetch_assoc($result)) {
@@ -1820,27 +1818,9 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
                        if ($row) {
                                // Add the row to the array:
                                $output[] = $row;
-                               // Set an internal register:
-                               $recs[$c] = $row['uid'];
-                               // Create the list of the next three ids (for editing links...)
-                               for ($a = 0; $a < $nextTree; $a++) {
-                                       $inList = GeneralUtility::inList($this->tt_contentData['nextThree'][$recs[$c - $a]], $row['uid']);
-                                       if (isset($recs[$c - $a]) && !$inList) {
-                                               $this->tt_contentData['nextThree'][$recs[$c - $a]] .= $row['uid'] . ',';
-                                       }
-                               }
-                               // Set next/previous ids:
-                               if (isset($recs[$c - 1])) {
-                                       if (isset($recs[$c - 2])) {
-                                               $this->tt_contentData['prev'][$row['uid']] = -$recs[($c - 2)];
-                                       } else {
-                                               $this->tt_contentData['prev'][$row['uid']] = $row['pid'];
-                                       }
-                                       $this->tt_contentData['next'][$recs[$c - 1]] = -$row['uid'];
-                               }
-                               $c++;
                        }
                }
+               $this->generateTtContentDataArray($output);
                // Return selected records
                return $output;
        }
@@ -1878,6 +1858,40 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
        }
 
        /**
+        * Generates the data for previous and next elements which is needed for movements.
+        *
+        * @param array $rowArray
+        * @return void
+        */
+       protected function generateTtContentDataArray(array $rowArray) {
+               $this->tt_contentData = array(
+                       'nextThree' => array(),
+                       'next' => array(),
+                       'prev' => array(),
+               );
+               foreach ($rowArray as $key => $value) {
+                       // Create the list of the next three ids (for editing links...)
+                       for ($i = 0; $i < $this->nextThree; $i++) {
+                               if (isset($rowArray[$key - $i])
+                                       && !GeneralUtility::inList($this->tt_contentData['nextThree'][$rowArray[$key - $i]['uid']], $value['uid'])
+                               ) {
+                                       $this->tt_contentData['nextThree'][$rowArray[$key - $i]['uid']] .= $value['uid'] . ',';
+                               }
+                       }
+
+                       // Create information for next and previous content elements
+                       if (isset($rowArray[$key - 1])) {
+                               if (isset($rowArray[$key - 2])) {
+                                       $this->tt_contentData['prev'][$value['uid']] = -$rowArray[$key - 2]['uid'];
+                               } else {
+                                       $this->tt_contentData['prev'][$value['uid']] = $value['pid'];
+                               }
+                               $this->tt_contentData['next'][$rowArray[$key - 1]['uid']] = -$value['uid'];
+                       }
+               }
+       }
+
+       /**
         * Counts and returns the number of records on the page with $pid
         *
         * @param string $table Table name