[TYPO3-english] Extbase handler for Ajax calls in BE and FE

Xavier Perseguers xavier at typo3.org
Mon Nov 25 11:13:11 CET 2013


Hi Jan,

> But still no news regarding extbase in BE :( If anybody has already used
> extbase together with ajax in BE, please let me know ;)

The Extension Manager is doing that. Example links are generated as
standard "<a href" links in the template, then are processed by jquery
(main.js):

$('.t3-icon-system-extension-update').parent().each(function() {
	$(this).data('href', $(this).attr('href'));
	$(this).attr('href', '#');
	$(this).addClass('transformed');
	$(this).click(function() {
		$('.typo3-extension-manager').mask();
		$.ajax({
			url: $(this).data('href'),
			dataType: 'json',
			success: updateExtension
		});
	});
});

dataType: 'json' will ask extbase to use JSON as return type and thus
instruct it to search for a .json template instead of .html.

remove extension is done slightly differently (link comes from the
confirmation dialog) but idea is the same:

if (button == 'yes') {
	$('.typo3-extension-manager').mask();
	$.ajax({
		url: dialog.url,
		dataType: 'json',
		success: removeExtension
	});
}

The controller action does nothing special:

/**
 * Remove an extension (if it is still installed, uninstall it first)
 *
 * @param string $extension
 */
protected function removeExtensionAction($extension) {
	$success = TRUE;
	$message = '';
	try {
		if
(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extension)) {
			$this->installUtility->uninstall($extension);
		}
		$this->installUtility->removeExtension($extension);
	} catch
(\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
		$message = $e->getMessage();
		$success = FALSE;
	}
	$this->view->assign('success', $success)->assign('message',
$message)->assign('extension', $extension);
}

and the corresponding view (RemoveExtension.json) is straightforward:

{namespace em=TYPO3\CMS\Extensionmanager\ViewHelpers}
<em:format.jsonEncode additionalAttributes="{success:success,
message:message, extension:extension}" />

So this is a full example on AJAX call to Extbase in Backend, not using
ExtJS (which is not so beloved anymore) but jQuery.

HTH

-- 
Xavier Perseguers
Release Manager TYPO3 4.6

TYPO3 .... inspiring people to share!
Get involved: http://typo3.org



More information about the TYPO3-english mailing list