Bug #56347
Document new API to register an Ajax handler for the backend
Status: | Resolved | Start date: | 2014-02-26 | |
---|---|---|---|---|
Priority: | Must have | Due date: | ||
Assigned To: | Francois Suter | % Done: | 100% |
|
Category: | - | |||
Target version: | 6.2 |
Description
New API has been added to register backend ajax handlers.
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerAjaxHandler('TxMyExt::process', '\Vendor\Ext\AjaxHanlder->process');
Along with that, new API has been added to get the Ajax URL for a given AjaxId.
This URL will contain a CSRF protection token that will be checked
in the ajax.php dispatcher:
$ajaxUrl = \TYPO3\CMS\Core\Utility\BackendUtility::getAjaxUrl('TxMyExt::process');
It is recommended that this URL is then passed to the page renderer inline settings:
$pageRenderer->addInlineSetting('MyExt', 'ajaxUrl', BackendUtility::getAjaxUrl('TxMyExt::process'));
These settings can then be easily accessed in JavaScript context of that page:
var ajaxUrl = TYPO3.settings.MyExt.ajaxUrl;
Related issues
Associated revisions
[FEATURE] New AJAX handle registration API
Demonstrate the new API to regsiter AJAX handlers in the TYPO3 BE.
Additionally the section about AJAX calls in the BE needs to be
fully updated.
Resolves: #56347
Releases: 6.2
Change-Id: I5f51df4bcc0cb982a6b308ffee76d048e74b5c5b
Reviewed-on: https://review.typo3.org/28920
Reviewed-by: Francois Suter
Tested-by: Francois Suter
History
#1 Updated by Helmut Hummel over 1 year ago
Registering an Ajax script the "old" way by just adding it to TYPO3_CONF_VARS is then deprecated.
#2 Updated by Francois Suter over 1 year ago
- Project changed from Documentation to Core APIs
#3 Updated by Francois Suter over 1 year ago
- Target version set to 6.2
#4 Updated by Michael Schams over 1 year ago
Hi, I am just documenting this new feature for the What's New Slides and stumbled across this ticket :-)
I am sure, you would pick this up yourself, but just in case... I assume the first code example should read:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerAjaxHandler('TxMyExt::process', '\Vendor\MyExt\AjaxHandler->process');
There is a typo in the second parameter: "AjaxHanlder" -> "AjaxHandler", and maybe use "MyExt" for consistency?
#5 Updated by Francois Suter over 1 year ago
- Status changed from New to Accepted
- Assigned To set to Francois Suter
- Priority changed from Should have to Must have
#6 Updated by Helmut Hummel over 1 year ago
Please be note that the API will slightly change to ease the use for extension developers and streamline the usage in core.
Here the updated description:
==========
New API has been added to register an Ajax handler for the backend.
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerAjaxHandler('TxMyExt::process', 'Vendor\\Ext\\AjaxHandler->process');
Along with that, URLs to all registered handlers will be
published to JavaScript inline settings and can be looked up
by providing the Ajax ID:
var ajaxUrl = TYPO3.settings.ajaxUrls['TxMyExt::process'];
Registering an Ajax script the "old" way by just adding it to TYPO3_CONF_VARS has been deprecated,
but no deprecation log is been written and the handler still work in a backwards compatible way.
==========
This also means that
\TYPO3\CMS\Core\Utility\BackendUtility::getAjaxUrl();
Is not meant to be called in user land code any more and the method has been marked internal.
Sorry for changing this so late, but I think it is a great API improvement which evolved by changing the JavaScript in the core along the way.
#7 Updated by Francois Suter over 1 year ago
Remove mention about missing documentation is What's new section and add link to updated chapter instead.
#8 Updated by Gerrit Code Review over 1 year ago
- Status changed from Accepted to Under Review
Patch set 1 for branch master of project Documentation/TYPO3/Reference/CoreApi has been pushed to the review server.
It is available at https://review.typo3.org/28920
#9 Updated by Francois Suter over 1 year ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 394593fafdb3fdc3ce73ad5f93ca0b5be8f5200e.