public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
if (true === isset($arguments['value'])) {
$value = $arguments['value'];
} else {
$value = $renderChildrenClosure();
}
$type = $arguments['type'];
if (gettype($value) === $type) {
return $value;
}
if (null !== $value) {
if ('ObjectStorage' === $type && 'array' === gettype($value)) {
/** @var ObjectManager $objectManager */
$objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
/** @var ObjectStorage $storage */
$storage = $objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage');
foreach ($value as $item) {
$storage->attach($item);
}
$value = $storage;
} elseif ('array' === $type && true === $value instanceof \Traversable) {
$value = iterator_to_array($value, false);
} elseif ('array' === $type) {
$value = [$value];
} else {
settype($value, $type);
}
} else {
if (true === isset($arguments['default'])) {
$default = $arguments['default'];
if (gettype($default) !== $type) {
throw new \RuntimeException('Supplied argument "default" is not of the type "' . $type . '"', 1364542576);
}
$value = $default;
} else {
switch ($type) {
case 'string':
$value = '';
break;
case 'integer':
$value = 0;
break;
case 'boolean':
$value = false;
break;
case 'float':
$value = 0.0;
break;
case 'array':
$value = [];
break;
case 'ObjectStorage':
$objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$value = $objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage');
break;
default:
throw new \RuntimeException('Provided argument "type" is not valid', 1364542884);
}
}
}
return $value;
}