[BUGFIX] t3editor: Load TS located in rootline 42/54242/7
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Fri, 29 Sep 2017 21:24:08 +0000 (23:24 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Wed, 4 Oct 2017 18:22:59 +0000 (20:22 +0200)
Adding 'pid' to the form, t3editor now loads the TypoScript
that is placed in any page of the current rootline.

Resolves: #82623
Releases: master
Change-Id: I9364bb4a60d475be52bbcc5079b4c3a6e9cb42ec
Reviewed-on: https://review.typo3.org/54242
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/t3editor/Classes/Form/Element/T3editorElement.php
typo3/sysext/t3editor/Resources/Public/JavaScript/Addon/Hint/TsCodeCompletion.js

index 662b98c..96bb8e1 100644 (file)
@@ -122,7 +122,10 @@ class T3editorElement extends AbstractFormElement
             $parameterArray['itemFormElValue'],
             $attributeString,
             $this->data['tableName'] . ' > ' . $this->data['fieldName'],
-            ['target' => 0]
+            [
+                'target' => 0,
+                'effectivePid' => $this->data['effectivePid']
+            ]
         );
 
         $fieldInformationResult = $this->renderFieldInformation();
index 4246713..be5a314 100644 (file)
@@ -39,17 +39,21 @@ define([
        /**
         * All external templates along the rootline have to be loaded,
         * this function retrieves the JSON code by committing a AJAX request
+        *
+        * @param {number} id
         */
-       TsCodeCompletion.loadExtTemplatesAsync = function() {
-               var id = TsCodeCompletion.getGetVar('id');
-               if (id === '') {
-                       return;
+       TsCodeCompletion.loadExtTemplatesAsync = function(id) {
+               // Ensure id is an integer
+               id *= 1;
+               if (isNaN(id) || id === 0) {
+                       return null;
                }
                $.ajax({
                        url: TYPO3.settings.ajaxUrls['t3editor_codecompletion_loadtemplates'],
                        data: {
                                pageId: id
                        },
+                       dataType: 'json',
                        success: function(response) {
                                TsCodeCompletion.extTsObjTree.c = response;
                                TsCodeCompletion.resolveExtReferencesRec(TsCodeCompletion.extTsObjTree.c);
@@ -57,46 +61,6 @@ define([
                });
        };
 
-       /**
-        * Get the value of a given GET parameter
-        *
-        * @param {String} name
-        * @return {String}
-        */
-       TsCodeCompletion.getGetVar = function(name) {
-               var get_string = document.location.search,
-                       return_value = '',
-                       value;
-
-               do { //This loop is made to catch all instances of any get variable.
-                       var name_index = get_string.indexOf(name + '=');
-                       if (name_index !== -1) {
-                               get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
-                               var end_of_value = get_string.indexOf('&');
-                               if (end_of_value !== -1) {
-                                       value = get_string.substr(0, end_of_value);
-                               } else {
-                                       value = get_string;
-                               }
-
-                               if (return_value === '' || value === '') {
-                                       return_value += value;
-                               } else {
-                                       return_value += ', ' + value;
-                               }
-                       }
-               } while (name_index !== -1);
-
-               // Restores all the blank spaces.
-               var space = return_value.indexOf('+');
-               while (space !== -1) {
-                       return_value = return_value.substr(0, space) + ' ' + return_value.substr(space + 1, return_value.length);
-                       space = return_value.indexOf('+');
-               }
-
-               return return_value;
-       };
-
        /**
         * Since the references are not resolved server side we have to do it client-side
         * Benefit: less loading time due to less data which has to be transmitted
@@ -201,8 +165,8 @@ define([
        $(function() {
                TsCodeCompletion.parser = TsParser.init(TsCodeCompletion.tsRef, TsCodeCompletion.extTsObjTree);
                TsCodeCompletion.tsRef.loadTsrefAsync();
-               TsCodeCompletion.loadExtTemplatesAsync();
+               TsCodeCompletion.loadExtTemplatesAsync($('input[name="effectivePid"]').first().val());
        });
 
        return TsCodeCompletion;
-});
\ No newline at end of file
+});