[BUGFIX] Folder tree in popup throws JS error 16/26816/2
authorAske Ertmann <aske@moc.net>
Tue, 26 Nov 2013 12:35:54 +0000 (13:35 +0100)
committerMarkus Klein <klein.t3@mfc-linz.at>
Tue, 14 Jan 2014 16:21:29 +0000 (17:21 +0100)
When using the folder tree (file, and folder navigation) popup
(browse_links) a JS error occurs when opening new folders.

This is due to incorrect handling of scope.
This patch fixes the error for both RTE and normal link browser.

Change-Id: I25fa0871405e06d6fc084985b3beba6396b872ad
Resolves: #53826
Releases: 6.0, 6.1, 6.2
Reviewed-on: https://review.typo3.org/26816
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/class.browse_links.php
typo3/sysext/backend/Classes/Tree/View/FolderTreeView.php
typo3/sysext/rtehtmlarea/Classes/FolderTree.php

index bab1c60..91cae9d 100644 (file)
@@ -292,11 +292,6 @@ class TBE_FolderTree extends localFolderTree {
        public $ext_noTempRecyclerDirs = 0;
 
        /**
-        * @var array
-        */
-       protected $scope;
-
-       /**
         * Returns TRUE if the input "record" contains a folder which can be linked.
         *
         * @param \TYPO3\CMS\Core\Resource\Folder $folderObject object with information about the folder element. Contains keys like title, uid, path, _title
@@ -327,29 +322,6 @@ class TBE_FolderTree extends localFolderTree {
                        return '<span class="typo3-dimmed">' . $title . '</span>';
                }
        }
-
-       /**
-        * Wrap the plus/minus icon in a link
-        *
-        * @param string $icon HTML string to wrap, probably an image tag.
-        * @param string $cmd Command for 'PM' get var
-        * @param boolean $isExpand Whether to be expanded
-        * @return string Link-wrapped input string
-        * @internal
-        */
-       public function PMiconATagWrap($icon, $cmd, $isExpand = TRUE) {
-               $this->scope = array(
-                       'class' => get_class($this),
-                       'script' => $this->thisScript,
-                       'ext_noTempRecyclerDirs' => $this->ext_noTempRecyclerDirs,
-                       'browser' => array(
-                               'mode' => $GLOBALS['SOBE']->browser->mode,
-                               'act' => $GLOBALS['SOBE']->browser->act,
-                       ),
-               );
-
-               return parent::PMiconATagWrap($icon, $cmd, $isExpand);
-       }
 }
 
 /*
@@ -358,4 +330,4 @@ class TBE_FolderTree extends localFolderTree {
  * typo3/sysext/recordlist/Classes/Browser/ElementBrowser.php
  */
 require_once \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('recordlist') . 'Classes/Browser/ElementBrowser.php';
-?>
\ No newline at end of file
+?>
index 4e97f1b..8d43e17 100644 (file)
@@ -57,6 +57,11 @@ class FolderTreeView extends \TYPO3\CMS\Backend\Tree\View\AbstractTreeView {
        protected $ajaxStatus = FALSE;
 
        /**
+        * @var array
+        */
+       protected $scope;
+
+       /**
         * Constructor function of the class
         */
        public function __construct() {
@@ -101,15 +106,23 @@ class FolderTreeView extends \TYPO3\CMS\Backend\Tree\View\AbstractTreeView {
         * @internal
         */
        public function PMiconATagWrap($icon, $cmd, $isExpand = TRUE) {
+
+               if (empty($this->scope)) {
+                       $this->scope = array(
+                               'class' => get_class($this),
+                               'script' => $this->thisScript,
+                               'ext_noTempRecyclerDirs' => $this->ext_noTempRecyclerDirs,
+                               'browser' => array(
+                                       'mode' => $GLOBALS['SOBE']->browser->mode,
+                                       'act' => $GLOBALS['SOBE']->browser->act,
+                               ),
+                       );
+               }
+
                if ($this->thisScript) {
                        // Activates dynamic AJAX based tree
-                       $scopeData = '';
-                       $scopeHash = '';
-                       // $this->scope is defined in TBE_FolderTree
-                       if (!empty($this->scope)) {
-                               $scopeData = serialize($this->scope);
-                               $scopeHash = \TYPO3\CMS\Core\Utility\GeneralUtility::hmac($scopeData);
-                       }
+                       $scopeData = serialize($this->scope);
+                       $scopeHash = \TYPO3\CMS\Core\Utility\GeneralUtility::hmac($scopeData);
                        $js = htmlspecialchars('Tree.load(\'' . $cmd . '\', ' . intval($isExpand) . ', this, \'' . $scopeData . '\', \'' . $scopeHash . '\');');
                        return '<a class="pm" onclick="' . $js . '">' . $icon . '</a>';
                } else {
index 82f950c..4f325d9 100644 (file)
@@ -10,6 +10,15 @@ namespace TYPO3\CMS\Rtehtmlarea;
 class FolderTree extends \rteFolderTree {
 
        /**
+        * Constructor function of the class
+        */
+       public function __construct() {
+               // The backpath is set her to fix problems with relatives path when used in ajax scope
+               $GLOBALS['BACK_PATH'] = isset($GLOBALS['ajaxID']) ? '../../../' : $GLOBALS['BACK_PATH'];
+               parent::__construct();
+       }
+
+       /**
         * Wrapping the title in a link, if applicable.
         *
         * @param       string                  Title, ready for output.
@@ -36,8 +45,24 @@ class FolderTree extends \rteFolderTree {
         * @access private
         */
        public function PMiconATagWrap($icon, $cmd, $isExpand = TRUE) {
+
+               if (empty($this->scope)) {
+                       $this->scope = array(
+                               'class' => get_class($this),
+                               'script' => $this->thisScript,
+                               'ext_noTempRecyclerDirs' => $this->ext_noTempRecyclerDirs,
+                               'browser' => array(
+                                       'mode' => $GLOBALS['SOBE']->browser->mode,
+                                       'act' => $GLOBALS['SOBE']->browser->act,
+                               ),
+                       );
+               }
+
                if ($this->thisScript) {
-                       $js = htmlspecialchars('Tree.thisScript=\'' . $GLOBALS['BACK_PATH'] . 'ajax.php\',Tree.load(\'' . $cmd . '\', ' . intval($isExpand) . ', this);');
+                       // Activates dynamic AJAX based tree
+                       $scopeData = serialize($this->scope);
+                       $scopeHash = \TYPO3\CMS\Core\Utility\GeneralUtility::hmac($scopeData);
+                       $js = htmlspecialchars('Tree.thisScript=\'' . $this->backPath . 'ajax.php\',Tree.load(\'' . $cmd . '\', ' . intval($isExpand) . ', this, ' . json_encode($scopeData) . ', \'' . $scopeHash . '\');');
                        return '<a class="pm" onclick="' . $js . '">' . $icon . '</a>';
                } else {
                        return $icon;
@@ -46,5 +71,4 @@ class FolderTree extends \rteFolderTree {
 
 }
 
-
-?>
\ No newline at end of file
+?>