Created
December 4, 2020 10:51
-
-
Save lorenzulrich/542a90fea5534ea8b8d960e880b1fb67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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