[TASK] Deprecate methods related to traditional AJAX request dispatching 66/47466/2
authorBenni Mack <benni@typo3.org>
Thu, 31 Mar 2016 16:42:10 +0000 (18:42 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 7 Apr 2016 11:30:30 +0000 (13:30 +0200)
The execution of traditional AJAX requests not registered
via routes is already deprecated with #73352, however
the registration and usage of the methods to add AJAX
endpoints haven't been deprecated yet.

The patch takes care of deprecating
    - BackendUtility->getAjaxUrl()
    - UriBuilder->buildUriFromAjaxId()

Resolves: #75340
Releases: master
Change-Id: I6adf7f7c868c87f08400aa548d5deb8febddd857
Reviewed-on: https://review.typo3.org/47466
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Form/Element/ImageManipulationElement.php
typo3/sysext/backend/Classes/Routing/UriBuilder.php
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/core/Classes/ExtDirect/ExtDirectApi.php
typo3/sysext/core/Classes/Page/PageRenderer.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-75340-MethodsRelatedToGeneratingTraditionalBackendAJAXURLs.rst [new file with mode: 0644]
typo3/sysext/rtehtmlarea/Classes/Extension/Spellchecker.php

index 95609d0..72a619b 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Backend\Form\Element;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Backend\Routing\UriBuilder;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException;
 use TYPO3\CMS\Core\Resource\File;
@@ -106,8 +107,10 @@ class ImageManipulationElement extends AbstractFormElement
             );
             $wizardData['token'] = GeneralUtility::hmac(implode('|', $wizardData), 'ImageManipulationWizard');
 
+            /** @var UriBuilder $uriBuilder */
+            $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
             $buttonAttributes = array(
-                'data-url' => BackendUtility::getAjaxUrl('wizard_image_manipulation', $wizardData),
+                'data-url' => $uriBuilder->buildUriFromRoute('ajax_wizard_image_manipulation', $wizardData),
                 'data-severity' => 'notice',
                 'data-image-name' => $file->getNameWithoutExtension(),
                 'data-image-uid' => $file->getUid(),
index b1dd6e3..ec3d2b3 100644 (file)
@@ -136,9 +136,11 @@ class UriBuilder
      * @param string $referenceType The type of reference to be generated (one of the constants)
      *
      * @return Uri The generated Uri
+     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, use the buildUriFromRoute() method
      */
     public function buildUriFromAjaxId($ajaxIdentifier, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
     {
+        GeneralUtility::logDeprecatedFunction();
         $parameters = array(
             'ajaxID' => $ajaxIdentifier
         ) + $parameters;
index 14561eb..044382d 100755 (executable)
@@ -3215,9 +3215,11 @@ class BackendUtility
      * @param string $ajaxIdentifier Identifier of the AJAX callback
      * @param array $urlParameters URL parameters that should be added as key value pairs
      * @return string Calculated URL
+     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, use the UriBuilder directly.
      */
     public static function getAjaxUrl($ajaxIdentifier, array $urlParameters = array())
     {
+        GeneralUtility::logDeprecatedFunction();
         /** @var UriBuilder $uriBuilder */
         $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
         try {
index c92574c..4c0c5c0 100755 (executable)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Core\ExtDirect;
 
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
+use TYPO3\CMS\Backend\Routing\UriBuilder;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
@@ -142,7 +143,9 @@ class ExtDirectApi
         if (TYPO3_MODE === 'FE') {
             $url = GeneralUtility::locationHeaderUrl('?eID=ExtDirect&action=route&namespace=' . rawurlencode($namespace));
         } else {
-            $url = BackendUtility::getAjaxUrl('ext_direct_route', array('namespace' => $namespace));
+            /** @var UriBuilder $uriBuilder */
+            $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
+            $url = $uriBuilder->buildUriFromRoute('ajax_ext_direct_route', ['namespace' => $namespace]);
         }
         return $url;
     }
index 9a01f32..7a6b7c7 100644 (file)
@@ -2156,6 +2156,7 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface
     protected function addAjaxUrlsToInlineSettings()
     {
         $ajaxUrls = array();
+        // Note: this method of adding Ajax URLs is @deprecated as of TYPO3 v8, and will be removed in TYPO3 v9
         foreach ($GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX'] as $ajaxHandler => $_) {
             $ajaxUrls[$ajaxHandler] = BackendUtility::getAjaxUrl($ajaxHandler);
         }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-75340-MethodsRelatedToGeneratingTraditionalBackendAJAXURLs.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-75340-MethodsRelatedToGeneratingTraditionalBackendAJAXURLs.rst
new file mode 100644 (file)
index 0000000..dcc5d39
--- /dev/null
@@ -0,0 +1,34 @@
+=================================================================================
+Deprecation: #75340 - Methods related to generating traditional Backend AJAX URLs
+=================================================================================
+
+Description
+===========
+
+The following methods have been marked as deprecated:
+
+* TYPO3\CMS\Backend\Utility\BackendUtility->getAjaxUrl()
+* TYPO3\CMS\Backend\Routing\UriBuilder->buildUriFromAjaxId()
+
+
+Impact
+======
+
+Calling one of the methods above will trigger a deprecation log entry.
+
+
+Affected Installations
+======================
+
+Any TYPO3 instance with a third party extension that calls one of the methods above.
+
+
+Migration
+=========
+
+Migrate to UriBuilder routes, which can be registered via Configuration/Backend/AjaxRoutes.php,
+and can be linked to like this:
+
+       /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
+       $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
+       $path = $uriBuilder->buildUriFromRoute('ajax_myroute');
\ No newline at end of file
index 73c1ccb..3bc915f 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Rtehtmlarea\Extension;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Backend\Routing\UriBuilder;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -94,7 +95,16 @@ class Spellchecker extends RteHtmlAreaApi
             $jsArray[] = 'RTEarea[editornumber].buttons.' . $button . '.contentISOLanguage = "' . $this->configuration['contentISOLanguage'] . '";';
             $jsArray[] = 'RTEarea[editornumber].buttons.' . $button . '.spellCheckerMode = "' . $spellCheckerMode . '";';
             $jsArray[] = 'RTEarea[editornumber].buttons.' . $button . '.enablePersonalDicts = ' . ($enablePersonalDicts ? 'true' : 'false') . ';';
-            $jsArray[] = 'RTEarea[editornumber].buttons.' . $button . '.path = "' . ($this->isFrontend() || $this->isFrontendEditActive() ? ($GLOBALS['TSFE']->absRefPrefix ? $GLOBALS['TSFE']->absRefPrefix : '') . 'index.php?eID=rtehtmlarea_spellchecker' : BackendUtility::getAjaxUrl('rtehtmlarea_spellchecker')) . '";';
+
+            // Get the eID script or the AJAX path
+            if ($this->isFrontend() || $this->isFrontendEditActive()) {
+                $path = ($GLOBALS['TSFE']->absRefPrefix ?: '') . 'index.php?eID=rtehtmlarea_spellchecker';
+            } else {
+                /** @var UriBuilder $uriBuilder */
+                $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
+                $path = $uriBuilder->buildUriFromRoute('ajax_rtehtmlarea_spellchecker');
+            }
+            $jsArray[] = 'RTEarea[editornumber].buttons.' . $button . '.path = "' . $path . '";';
         }
         return implode(LF, $jsArray);
     }