Skip to content

Instantly share code, notes, and snippets.

@lorenzulrich
Created December 4, 2020 10:51
Show Gist options
  • Save lorenzulrich/542a90fea5534ea8b8d960e880b1fb67 to your computer and use it in GitHub Desktop.
Save lorenzulrich/542a90fea5534ea8b8d960e880b1fb67 to your computer and use it in GitHub Desktop.
<?php
/**
* This file is part of the "foobarsite" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
namespace Visol\Foobarsite\ViewHelpers;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* View helper which returns the time offset respecting Central European Summer Time (Daylight Saving Time)
*/
class DataMapperViewHelper extends AbstractViewHelper
{
/**
* @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper
* @inject
*/
protected $dataMapper;
/**
* @param string $targetType
* @param array $records An array of records to map
* @param array $record A single record to map
*
* @return array
*/
public function render($targetType, $records = [], $record = [])
{
if (!empty($record)) {
// Map and return exactly one record
$records = $this->dataMapper->map($targetType, [$record]);
if (count($records)) {
return $records[0];
}
} else {
// Map and return all records
return $this->dataMapper->map($targetType, $records);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment