[!!!][TASK] Streamline ElementBrowser mode handling 75/42875/4
authorMarkus Klein <markus.klein@typo3.org>
Tue, 25 Aug 2015 16:37:23 +0000 (18:37 +0200)
committerBenni Mack <benni@typo3.org>
Tue, 25 Aug 2015 20:06:36 +0000 (22:06 +0200)
The ElementBrowser now has a main entry point which takes
care of dispatching to the the various modes.
The main_*() methods of ElementBrowser are therefore made protected.

The $mode member of ElementBrowserController is not needed
by outside code and is therefore protected as well.

Additionally, the $content member of ElementBrowserController and
the printContent() method are removed.

Resolves: #69315
Releases: master
Change-Id: Ib9790915e72d3a5a460211a93ceeda24ee165c3e
Reviewed-on: http://review.typo3.org/42875
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Breaking-69315-ElementBrowsermain_Protected.rst [new file with mode: 0644]
typo3/sysext/recordlist/Classes/Browser/ElementBrowser.php
typo3/sysext/recordlist/Classes/Controller/ElementBrowserController.php
typo3/sysext/rtehtmlarea/Classes/BrowseLinks.php
typo3/sysext/rtehtmlarea/Classes/SelectImage.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-69315-ElementBrowsermain_Protected.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-69315-ElementBrowsermain_Protected.rst
new file mode 100644 (file)
index 0000000..c6630a7
--- /dev/null
@@ -0,0 +1,28 @@
+===================================================
+Breaking: #69315 - ElementBrowser::main_* protected
+===================================================
+
+Description
+===========
+
+The ``ElementBrowser::main_*`` methods have been marked protected as the new ``render`` method is the main entry point to the class.
+Additionally the public member ``ElementBrowserController::mode`` has been protected as well.
+
+The ``ElementBrowserController::content`` member and the ``ElementBrowserController::printContent()`` method have been removed.
+
+Impact
+======
+
+Any code calling the protected or removed methods or using the protected member will fail with a fatal error.
+Any code using the removed member, will receive only an empty value. (PHP fallback for non-existing class members)
+
+Affected Installations
+======================
+
+Any installation using third party code calling the mentioned methods or member.
+
+
+Migration
+=========
+
+Ensure the intended mode is passed in via the ``mode`` GET-parameter and call the new ``ElementBrowser::render`` method.
index b19e9a6..9553333 100755 (executable)
@@ -832,7 +832,7 @@ class ElementBrowser {
         */
        public function processSessionData($data) {
                $store = FALSE;
-               switch ((string)$this->mode) {
+               switch ($this->mode) {
                        case 'db':
                                if (isset($this->expandPage)) {
                                        $data['expandPage'] = $this->expandPage;
@@ -862,6 +862,30 @@ class ElementBrowser {
         * Main functions
         *
         ******************************************************************/
+
+       /**
+        * Main entry point
+        *
+        * @return string HTML output
+        */
+       public function render() {
+               // Output the correct content according to $this->mode
+               switch ($this->mode) {
+                       case 'rte':
+                               return $this->main_rte();
+                       case 'db':
+                               return $this->main_db();
+                       case 'file':
+                       case 'filedrag':
+                               return $this->main_file();
+                       case 'folder':
+                               return $this->main_folder();
+                       case 'wizard':
+                               return $this->main_rte(TRUE);
+               }
+               return '';
+       }
+
        /**
         * Rich Text Editor (RTE) link selector (MAIN function)
         * Generates the link selector for the Rich Text Editor.
@@ -870,7 +894,7 @@ class ElementBrowser {
         * @param bool $wiz If set, the "remove link" is not shown in the menu: Used for the "Select link" wizard which is used by the TCEforms
         * @return string Modified content variable.
         */
-       public function main_rte($wiz = FALSE) {
+       protected function main_rte($wiz = FALSE) {
                // needs to be executed before doc->startPage()
                if (in_array($this->act, array('file', 'folder'))) {
                        $this->doc->getDragDropCode('folders', 'Tree.ajaxID = "SC_alt_file_navframe::expandCollapse"');
@@ -1295,7 +1319,7 @@ class ElementBrowser {
         *
         * @return string HTML content for the module
         */
-       public function main_db() {
+       protected function main_db() {
                // Starting content:
                $content = $this->doc->startPage('TBE record selector');
                // Init variable:
@@ -1366,7 +1390,7 @@ class ElementBrowser {
         *
         * @return string HTML content for the module
         */
-       public function main_file() {
+       protected function main_file() {
                // include JS files and set prefs for foldertree
                $this->doc->getDragDropCode('folders', 'Tree.ajaxID = "SC_alt_file_navframe::expandCollapse"');
                // Starting content:
@@ -1497,7 +1521,7 @@ class ElementBrowser {
         *
         * @return string HTML content for the module
         */
-       public function main_folder() {
+       protected function main_folder() {
                // include JS files
                // Setting prefs for foldertree
                $this->doc->getDragDropCode('folders', 'Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";');
index def91e9..ea44225 100644 (file)
@@ -30,16 +30,17 @@ class ElementBrowserController implements \TYPO3\CMS\Core\Http\ControllerInterfa
 
        /**
         * The mode determines the main kind of output of the element browser.
+        *
         * There are these options for values:
         *  - "rte" will show the link selector for the Rich Text Editor (see main_rte())
         *  - "wizard" will allow you to browse for links (like "rte") which are passed back to FormEngine (see main_rte(TRUE))
         *  - "db" will allow you to browse for pages or records in the page tree for FormEngine select fields (see main_db())
         *  - "file"/"filedrag" will allow you to browse for files in the folder mounts for FormEngine file selections (main_file())
-        *  - "folder" will allow you to browse for folders in the folder mounts for FormEngine folder selecitons (see main_folder())
+        *  - "folder" will allow you to browse for folders in the folder mounts for FormEngine folder selections (see main_folder())
         *
         * @var string
         */
-       public $mode;
+       protected $mode;
 
        /**
         * Document template object
@@ -49,11 +50,6 @@ class ElementBrowserController implements \TYPO3\CMS\Core\Http\ControllerInterfa
        public $doc;
 
        /**
-        * @var string
-        */
-       public $content = '';
-
-       /**
         * Constructor
         */
        public function __construct() {
@@ -85,23 +81,21 @@ class ElementBrowserController implements \TYPO3\CMS\Core\Http\ControllerInterfa
         * @return ResponseInterface $response
         */
        public function processRequest(ServerRequestInterface $request) {
-               $this->main();
-
                /** @var Response $response */
                $response = GeneralUtility::makeInstance(Response::class);
-               $response->getBody()->write($this->content);
+               $response->getBody()->write($this->main());
                return $response;
        }
 
        /**
         * Main function, detecting the current mode of the element browser and branching out to internal methods.
         *
-        * @return void
+        * @return string HTML content
         */
        public function main() {
                $this->setTemporaryDbMounts();
 
-               $this->content = '';
+               $content = '';
 
                // Render type by user func
                $browserRendered = FALSE;
@@ -110,7 +104,7 @@ class ElementBrowserController implements \TYPO3\CMS\Core\Http\ControllerInterfa
                                $browserRenderObj = GeneralUtility::getUserObj($classRef);
                                if (is_object($browserRenderObj) && method_exists($browserRenderObj, 'isValid') && method_exists($browserRenderObj, 'render')) {
                                        if ($browserRenderObj->isValid($this->mode, $this)) {
-                                               $this->content .= $browserRenderObj->render($this->mode, $this);
+                                               $content .= $browserRenderObj->render($this->mode, $this);
                                                $browserRendered = TRUE;
                                                break;
                                        }
@@ -125,27 +119,10 @@ class ElementBrowserController implements \TYPO3\CMS\Core\Http\ControllerInterfa
                        $modData = $backendUser->getModuleData('browse_links.php', 'ses');
                        list($modData) = $browser->processSessionData($modData);
                        $backendUser->pushModuleData('browse_links.php', $modData);
-
-                       // Output the correct content according to $this->mode
-                       switch ((string)$this->mode) {
-                               case 'rte':
-                                       $this->content = $browser->main_rte();
-                                       break;
-                               case 'db':
-                                       $this->content = $browser->main_db();
-                                       break;
-                               case 'file':
-                               case 'filedrag':
-                                       $this->content = $browser->main_file();
-                                       break;
-                               case 'folder':
-                                       $this->content = $browser->main_folder();
-                                       break;
-                               case 'wizard':
-                                       $this->content = $browser->main_rte(TRUE);
-                                       break;
-                       }
+                       $content .= $browser->render();
                }
+
+               return $content;
        }
 
        /**
@@ -192,17 +169,6 @@ class ElementBrowserController implements \TYPO3\CMS\Core\Http\ControllerInterfa
        }
 
        /**
-        * Print module content
-        *
-        * @return void
-        * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, use processRequest() instead
-        */
-       public function printContent() {
-               GeneralUtility::logDeprecatedFunction();
-               echo $this->content;
-       }
-
-       /**
         * @return LanguageService
         */
        protected function getLanguageService() {
index 8e053b2..2235312 100644 (file)
@@ -399,7 +399,7 @@ class BrowseLinks extends ElementBrowser {
         * @param bool $wiz If set, the "remove link" is not shown in the menu: Used for the "Select link" wizard which is used by the TCEforms
         * @return string Modified content variable.
         */
-       public function main_rte($wiz = FALSE) {
+       protected function main_rte($wiz = FALSE) {
                // Starting content:
                $content = $this->doc->startPage($this->getLanguageService()->getLL('Insert/Modify Link', TRUE));
                // Making menu in top:
index db08c29..4c1247a 100644 (file)
@@ -383,7 +383,7 @@ plugin.insertImage(imageTags.join(\' \'));
         * @return string Modified content variable.
         * @return string
         */
-       public function main_rte($wiz = FALSE) {
+       protected function main_rte($wiz = FALSE) {
                // Starting content:
                $lang = $this->getLanguageService();
                $this->content = $this->doc->startPage($lang->getLL('Insert Image', TRUE));