Skip to content

Instantly share code, notes, and snippets.

@kitzberger
Last active April 24, 2018 17:21
Show Gist options
  • Save kitzberger/5991952013daebcb205388e309b635f6 to your computer and use it in GitHub Desktop.
Save kitzberger/5991952013daebcb205388e309b635f6 to your computer and use it in GitHub Desktop.
<?php
namespace Vendor\Extension\View\Record;
class ListJson extends \TYPO3\CMS\Extbase\Mvc\View\JsonView {
private static $uriBuilder = null;
public function typolink($page, $uid = null) {
if ($page) {
if (self::$uriBuilder === null) {
self::$uriBuilder = $this->controllerContext->getUriBuilder();
}
self::$uriBuilder->reset();
if ($uid) {
self::$uriBuilder->setArguments(array('tx_extension_list[uid]' => (int)$uid));
self::$uriBuilder->setUseCacheHash(true);
}
self::$uriBuilder->setTargetPageUid($page);
return self::$uriBuilder->build();
}
return '';
}
/**
* Renders the view
* @return string The rendered view as JSON
*/
public function render() {
// This should be set by \TYPO3\CMS\Extbase\Mvc\View\JsonView,
// but for some reason that's not working. Maybe related to this
// issue: https://forge.typo3.org/issues/60624
//
// The following option has to be set, in order to get this working:
// 'page.config.disableCharsetHeader = 1'
header('Content-Type: application/json; charset=utf-8');
$records = array();
foreach ($this->variables['records'] as $record) {
$records[] = $record->toArray($this);
}
return json_encode($records);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment