[TASK] Deprecate PageRenderer->loadJQuery() 55/58455/11
authorBenni Mack <benni@typo3.org>
Sat, 29 Sep 2018 13:11:00 +0000 (15:11 +0200)
committerBenni Mack <benni@typo3.org>
Sat, 29 Sep 2018 20:02:32 +0000 (22:02 +0200)
Instead of explicitly call loadJQuery() this should be handled
by requireJS or - even better - use vanilla JavaScript instead.

Resolves: #86438
Releases: master
Change-Id: Iecc2ceb7fa01578b00a63262f393bd1b92fa13e1
Reviewed-on: https://review.typo3.org/58455
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
19 files changed:
typo3/sysext/backend/Classes/Controller/BackendController.php
typo3/sysext/backend/Classes/Controller/LinkBrowserController.php
typo3/sysext/backend/Classes/Controller/PageLayoutController.php
typo3/sysext/backend/Classes/Form/FormResultCompiler.php
typo3/sysext/backend/Classes/Template/DocumentTemplate.php
typo3/sysext/backend/Classes/Template/ModuleTemplate.php
typo3/sysext/core/Classes/Page/PageRenderer.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-86438-DeprecatePageRenderer-loadJQuery.rst [new file with mode: 0644]
typo3/sysext/core/Tests/Functional/Page/PageRendererTest.php
typo3/sysext/core/Tests/Unit/Page/PageRendererTest.php
typo3/sysext/core/Tests/UnitDeprecated/Page/PageRendererTest.php [new file with mode: 0644]
typo3/sysext/frontend/Classes/Http/RequestHandler.php
typo3/sysext/frontend/Classes/Page/PageGenerator.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassConstantMatcher.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php
typo3/sysext/linkvalidator/Classes/Report/LinkValidatorReport.php
typo3/sysext/recordlist/Classes/Browser/AbstractElementBrowser.php
typo3/sysext/recordlist/Classes/Controller/RecordListController.php
typo3/sysext/scheduler/Classes/Controller/SchedulerModuleController.php

index e6669bf..fded85f 100644 (file)
@@ -131,8 +131,6 @@ class BackendController
         $this->moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
         $this->moduleLoader->load($GLOBALS['TBE_MODULES']);
         $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
-        // included for the module menu JavaScript, please note that this is subject to change
-        $this->pageRenderer->loadJquery();
         // Add default BE javascript
         $this->jsFiles = [
             'md5' => 'EXT:backend/Resources/Public/JavaScript/md5.js',
index 572a803..3f6da45 100644 (file)
@@ -70,7 +70,6 @@ class LinkBrowserController extends AbstractLinkBrowserController
         $inlineJS = implode(LF, $update);
 
         $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
-        $pageRenderer->loadJquery();
         $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/FormEngineLinkBrowserAdapter', 'function(FormEngineLinkBrowserAdapter) {
                        FormEngineLinkBrowserAdapter.updateFunctions = function() {' . $inlineJS . '};
                }');
index 5ce1b74..c2c9a63 100644 (file)
@@ -817,7 +817,6 @@ class PageLayoutController
     {
         $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
 
-        $this->moduleTemplate->getPageRenderer()->loadJquery();
         $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
         $dbList = GeneralUtility::makeInstance(PageLayoutView::class);
         $dbList->thumbs = $this->imagemode;
index 191ad96..a9aae2a 100644 (file)
@@ -18,6 +18,7 @@ use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Form\Domain\Model\FormElements\Page;
 
 /**
  * This is form engine - Class for creating the backend editing forms.
@@ -217,7 +218,6 @@ class FormResultCompiler
                 $pageRenderer->loadRequireJsModule($moduleName, $callback);
             }
         }
-        $pageRenderer->loadJquery();
         $backendUser = $this->getBackendUserAuthentication();
 
         // define the window size of the element browser etc.
@@ -267,7 +267,8 @@ class FormResultCompiler
                 $pageRenderer->addInlineLanguageLabelFile($additionalInlineLanguageLabelFile);
             }
         }
-        // We want to load jQuery-ui inside our js. Enable this using requirejs.
+        // @TODO: Refactor jsfunc.inline.js to an AMD module / TypsScript. If this is done, remove loadJquery() call.
+        $pageRenderer->loadJquery(null, null, PageRenderer::JQUERY_NAMESPACE_NONE, true);
         $pageRenderer->addJsFile('EXT:backend/Resources/Public/JavaScript/jsfunc.inline.js');
 
         // todo: change these things in JS
index 1cf9fb5..8197cf2 100644 (file)
@@ -510,11 +510,10 @@ function jumpToUrl(URL) {
             $this->pageRenderer->addJsInlineCode($name, $code, false);
         }
 
-        // Load jquery and twbs JS libraries on every backend request
-        $this->pageRenderer->loadJquery();
         // Note: please do not reference "bootstrap" outside of the TYPO3 Core (not in your own extensions)
         // as this is preliminary as long as Twitter bootstrap does not support AMD modules
         // this logic will be changed once Twitter bootstrap 4 is included
+        // @todo
         $this->pageRenderer->addJsFile('EXT:core/Resources/Public/JavaScript/Contrib/bootstrap/bootstrap.js');
 
         // csh manual require js module & moduleUrl
index e9d4c8c..a5a25bc 100644 (file)
@@ -265,7 +265,6 @@ class ModuleTemplate
      */
     protected function loadJavaScripts()
     {
-        $this->pageRenderer->loadJquery();
         $this->pageRenderer->loadRequireJsModule('bootstrap');
         $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextHelp');
         $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DocumentHeader');
index 4161aa3..37e9abf 100644 (file)
@@ -38,9 +38,11 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface
     const PART_COMPLETE = 0;
     const PART_HEADER = 1;
     const PART_FOOTER = 2;
+    // @deprecated will be removed in TYPO3 v10.0.
     // jQuery Core version that is shipped with TYPO3
     const JQUERY_VERSION_LATEST = '3.3.1';
     // jQuery namespace options
+    // @deprecated will be removed in TYPO3 v10.0.
     const JQUERY_NAMESPACE_NONE = 'none';
 
     /**
@@ -276,6 +278,7 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface
      * The local directory where one can find jQuery versions and plugins
      *
      * @var string
+     * @deprecated will be removed in TYPO3 v10.0.
      */
     protected $jQueryPath = 'EXT:core/Resources/Public/JavaScript/Contrib/jquery/';
 
@@ -296,6 +299,7 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface
      * jQuery core out of the box.
      *
      * @var array
+     * @deprecated will be removed in TYPO3 v10.0.
      */
     protected $jQueryVersions = [];
 
@@ -303,6 +307,7 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface
      * Array of jQuery version numbers shipped with the core
      *
      * @var array
+     * @deprecated will be removed in TYPO3 v10.0.
      */
     protected $availableLocalJqueryVersions = [
         self::JQUERY_VERSION_LATEST
@@ -1356,10 +1361,15 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface
      * @param string|null $version The jQuery version that should be included, either "latest" or any available version
      * @param string|null $source The location of the jQuery source, can be "local", "google", "msn", "jquery" or just an URL to your jQuery lib
      * @param string $namespace The namespace in which the jQuery object of the specific version should be stored.
+     * @param bool $isCoreCall if set, then the deprecation message is suppressed.
      * @throws \UnexpectedValueException
+     * @deprecated since TYPO3 v9.5, will be removed in TYPO3 v10.0. This is still in use in deprecated code, so it does not trigger a deprecation warning.
      */
-    public function loadJquery($version = null, $source = null, $namespace = self::JQUERY_NAMESPACE_NONE)
+    public function loadJquery($version = null, $source = null, $namespace = self::JQUERY_NAMESPACE_NONE, bool $isCoreCall = false)
     {
+        if (!$isCoreCall) {
+            trigger_error('PageRenderer->loadJquery() will be removed in TYPO3 v10.0. Use a package manager for frontend or custom jQuery files instead.', E_USER_DEPRECATED);
+        }
         // Set it to the version that is shipped with the TYPO3 core
         if ($version === null || $version === 'latest') {
             $version = self::JQUERY_VERSION_LATEST;
@@ -1430,6 +1440,7 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface
         $corePath = PathUtility::getAbsoluteWebPath($corePath);
         // first, load all paths for the namespaces, and configure contrib libs.
         $requireJsConfig['paths'] = [
+            'jquery' => $corePath . '/jquery/jquery',
             'jquery-ui' => $corePath . 'jquery-ui',
             'datatables' => $corePath . 'jquery.dataTables',
             'nprogress' => $corePath . 'nprogress',
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-86438-DeprecatePageRenderer-loadJQuery.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-86438-DeprecatePageRenderer-loadJQuery.rst
new file mode 100644 (file)
index 0000000..cc062de
--- /dev/null
@@ -0,0 +1,32 @@
+.. include:: ../../Includes.txt
+
+==========================================================
+Deprecation: #86438 - Deprecate PageRenderer->loadJQuery()
+==========================================================
+
+See :issue:`86438`
+
+Description
+===========
+
+The method :php:`PageRenderer->loadJQuery()` and the constants :php:`PageRenderer::JQUERY_VERSION_LATEST` and :php:`PageRenderer::JQUERY_NAMESPACE_NONE` have been marked as deprecated.
+
+
+Impact
+======
+
+Calling this method will trigger a PHP deprecation notice.
+
+
+Affected Installations
+======================
+
+TYPO3 installations with custom or thrid party extensions, which use the method.
+
+
+Migration
+=========
+
+Use a package manager for frontend or custom jQuery files instead.
+
+.. index:: Backend, Frontend, PHP-API, FullyScanned
index 9e270f9..abb3b68 100644 (file)
@@ -85,7 +85,7 @@ class PageRendererTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
         $subject->addCssInlineBlock('general2', 'body {margin:20px;}');
         $subject->addCssInlineBlock('general3', 'h1 {margin:20px;}', null, true);
 
-        $subject->loadJquery();
+        $subject->loadJquery(null, null, PageRenderer::JQUERY_NAMESPACE_NONE, true);
         $expectedJqueryRegExp = '#<script src="typo3/sysext/core/Resources/Public/JavaScript/Contrib/jquery/jquery\\.min\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
 
         $expectedBodyContent = $this->getUniqueId('ABCDE-');
@@ -208,7 +208,7 @@ class PageRendererTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
 
         $expectedRegExp = '#<script src="typo3/sysext/core/Resources/Public/JavaScript/Contrib/jquery/jquery\\.min\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
         $noConflictStatement = 'jQuery.noConflict();';
-        $subject->loadJquery(null, null, $namespace);
+        $subject->loadJquery(null, null, $namespace, true);
 
         //jQuery.noConflict();
         $out = $subject->render();
@@ -230,7 +230,7 @@ class PageRendererTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
 
         $expectedRegExp = '#<script src="typo3/sysext/core/Resources/Public/JavaScript/Contrib/jquery/jquery\\.min\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
         $expectedStatement = 'jQuery.noConflict();';
-        $subject->loadJquery(null, null, 'MyNameSpace');
+        $subject->loadJquery(null, null, 'MyNameSpace', true);
         $out = $subject->render();
         $this->assertRegExp($expectedRegExp, $out);
         $this->assertContains($expectedStatement, $out);
@@ -245,7 +245,7 @@ class PageRendererTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
         $subject = new PageRenderer();
 
         $expectedRegExp = '#<script src="typo3/sysext/core/Resources/Public/JavaScript/Contrib/jquery/jquery\\.min\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
-        $subject->loadJquery(null, null, PageRenderer::JQUERY_NAMESPACE_NONE);
+        $subject->loadJquery(null, null, PageRenderer::JQUERY_NAMESPACE_NONE, true);
         $out = $subject->render();
         $this->assertRegExp($expectedRegExp, $out);
         $this->assertNotContains('jQuery.noConflict', $out);
@@ -260,7 +260,7 @@ class PageRendererTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
 
         $expectedRegExp = '#<script src="typo3/sysext/core/Resources/Public/JavaScript/Contrib/jquery/jquery\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
         $expectedStatement = 'jQuery.noConflict();';
-        $subject->loadJquery(null, null, 'MyNameSpace');
+        $subject->loadJquery(null, null, 'MyNameSpace', true);
         $subject->enableDebugMode();
         $out = $subject->render();
         $this->assertRegExp($expectedRegExp, $out);
@@ -307,7 +307,7 @@ class PageRendererTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
     {
         $subject = new PageRenderer();
 
-        $subject->loadJquery($version, $source);
+        $subject->loadJquery($version, $source, PageRenderer::JQUERY_NAMESPACE_NONE, true);
         $subject->enableDebugMode();
         $out = $subject->render();
         $this->assertRegExp($regex, $out);
@@ -321,7 +321,7 @@ class PageRendererTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
         $subject = new PageRenderer();
 
         $expectedRegex = '#<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js" type="text/javascript"></script>#';
-        $subject->loadJquery('1.6.3', 'google');
+        $subject->loadJquery('1.6.3', 'google', PageRenderer::JQUERY_NAMESPACE_NONE, true);
         $out = $subject->render();
         $this->assertRegExp($expectedRegex, $out);
     }
index d40a05e..d0af842 100644 (file)
@@ -45,34 +45,6 @@ class PageRendererTest extends UnitTestCase
     /**
      * @test
      */
-    public function includingNotAvailableLocalJqueryVersionThrowsException()
-    {
-        $this->expectException(\UnexpectedValueException::class);
-        $this->expectExceptionCode(1341505305);
-
-        /** @var PageRenderer|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface $subject */
-        $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
-        $subject->_set('availableLocalJqueryVersions', ['1.1.1']);
-        $subject->loadJquery('2.2.2');
-    }
-
-    /**
-     * @test
-     */
-    public function includingJqueryWithNonAlphnumericNamespaceThrowsException()
-    {
-        $this->expectException(\UnexpectedValueException::class);
-        $this->expectExceptionCode(1341571604);
-
-        /** @var PageRenderer|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface $subject */
-        $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
-        $subject->loadJquery(null, null, '12sd.12fsd');
-        $subject->render();
-    }
-
-    /**
-     * @test
-     */
     public function addBodyContentAddsContent()
     {
         /** @var PageRenderer|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface $subject */
diff --git a/typo3/sysext/core/Tests/UnitDeprecated/Page/PageRendererTest.php b/typo3/sysext/core/Tests/UnitDeprecated/Page/PageRendererTest.php
new file mode 100644 (file)
index 0000000..63969f3
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\UnitDeprecated\Page;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Page\PageRenderer;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+
+/**
+ * Test case
+ */
+class PageRendererTest extends UnitTestCase
+{
+    /**
+     * @test
+     */
+    public function includingNotAvailableLocalJqueryVersionThrowsException()
+    {
+        $this->expectException(\UnexpectedValueException::class);
+        $this->expectExceptionCode(1341505305);
+
+        /** @var PageRenderer|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface $subject */
+        $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
+        $subject->_set('availableLocalJqueryVersions', ['1.1.1']);
+        $subject->loadJquery('2.2.2');
+    }
+
+    /**
+     * @test
+     */
+    public function includingJqueryWithNonAlphnumericNamespaceThrowsException()
+    {
+        $this->expectException(\UnexpectedValueException::class);
+        $this->expectExceptionCode(1341571604);
+
+        /** @var PageRenderer|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface $subject */
+        $subject = $this->getAccessibleMock(PageRenderer::class, ['dummy'], [], '', false);
+        $subject->loadJquery(null, null, '12sd.12fsd');
+        $subject->render();
+    }
+}
index 39ef14d..0ca7c3d 100644 (file)
@@ -513,7 +513,7 @@ class RequestHandler implements RequestHandlerInterface, PsrRequestHandlerInterf
                 } else {
                     $namespace = PageRenderer::JQUERY_NAMESPACE_NONE;
                 }
-                $pageRenderer->loadJquery($version, $source, $namespace);
+                $pageRenderer->loadJquery($version, $source, $namespace, true);
             }
         }
         // JavaScript library files
index 390f9bc..9d24c3c 100644 (file)
@@ -406,7 +406,7 @@ class PageGenerator
                 } else {
                     $namespace = PageRenderer::JQUERY_NAMESPACE_NONE;
                 }
-                $pageRenderer->loadJquery($version, $source, $namespace);
+                $pageRenderer->loadJquery($version, $source, $namespace, true);
             }
         }
         // JavaScript library files
index d74b442..ae00ae2 100644 (file)
@@ -130,4 +130,14 @@ return [
             'Deprecation-86406-TCATypeGroupInternal_typeFileAndFile_reference.rst',
         ],
     ],
+    'TYPO3\CMS\Core\Page\PageRenderer::JQUERY_VERSION_LATEST' => [
+        'restFiles' => [
+            'Deprecation-86438-DeprecatePageRenderer-loadJQuery.rst',
+        ],
+    ],
+    'TYPO3\CMS\Core\Page\PageRenderer::JQUERY_NAMESPACE_NONE' => [
+        'restFiles' => [
+            'Deprecation-86438-DeprecatePageRenderer-loadJQuery.rst',
+        ],
+    ],
 ];
index 04dd6c9..c3fc76c 100644 (file)
@@ -3684,4 +3684,11 @@ return [
             'Deprecation-86441-VariousMethodsAndPropertiesInsideBackendUserAuthentication.rst'
         ],
     ],
+    'TYPO3\CMS\Core\Page\PageRenderer->loadJquery' => [
+        'numberOfMandatoryArguments' => 0,
+        'maximumNumberOfArguments' => 3,
+        'restFiles' => [
+            'Deprecation-86438-DeprecatePageRenderer-loadJQuery.rst'
+        ],
+    ],
 ];
index 3476174..ac07d05 100644 (file)
@@ -360,7 +360,6 @@ class LinkValidatorReport
 
         $pageRenderer = $this->getPageRenderer();
         $pageRenderer->addCssFile('EXT:linkvalidator/Resources/Public/Css/linkvalidator.css', 'stylesheet', 'screen');
-        $pageRenderer->loadJquery();
         $pageRenderer->loadRequireJsModule('TYPO3/CMS/Linkvalidator/Linkvalidator');
 
         $this->templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class);
index 98479bc..c70cf01 100644 (file)
@@ -83,7 +83,6 @@ abstract class AbstractElementBrowser
         $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
         $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
         $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
-        $this->pageRenderer->loadJquery();
         $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Recordlist/ElementBrowser');
 
         $this->initialize();
index b3e318b..2e45050 100644 (file)
@@ -254,7 +254,6 @@ class RecordListController
     {
         $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
         $this->getLanguageService()->includeLLFile('EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf');
-        $this->moduleTemplate->getPageRenderer()->loadJquery();
         $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Recordlist/FieldSelectBox');
         $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Recordlist/Recordlist');
     }
index d6a181e..3eb0f96 100644 (file)
@@ -634,7 +634,6 @@ class SchedulerModuleController
         }
 
         // Load necessary JavaScript
-        $this->getPageRenderer()->loadJquery();
         $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Scheduler/Scheduler');
         $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/DateTimePicker');
         $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Scheduler/PageBrowser');
@@ -881,7 +880,6 @@ class SchedulerModuleController
             return $this->view->render();
         }
 
-        $this->getPageRenderer()->loadJquery();
         $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Scheduler/Scheduler');
         $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');