Files
oberstufe-alt/typo3conf/ext/vhs/Classes/ViewHelpers/Resource/CollectionViewHelper.php
2018-04-02 08:07:38 +02:00

60 lines
1.5 KiB
PHP

<?php
namespace FluidTYPO3\Vhs\ViewHelpers\Resource;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use TYPO3\CMS\Core\Collection\RecordCollectionRepository;
/**
* ### Collection ViewHelper
* This viewhelper returns a collection referenced by uid.
* For more information look here:
* http://docs.typo3.org/typo3cms/CoreApiReference/6.2/ApiOverview/Collections/Index.html#collections-api
*
* ### Example
* {v:resource.collection(uid:'123') -> v:var.set(name: 'someCollection')}
*
* @category ViewHelpers
* @package Vhs
* @author Dmitri Pisarev <dimaip@gmail.com>
*/
class CollectionViewHelper extends AbstractResourceViewHelper {
/**
* @var RecordCollectionRepository
*/
protected $collectionRepository;
/**
* @param RecordCollectionRepository $collectionRepository
* @return void
*/
public function injectCollectionRepository(RecordCollectionRepository $collectionRepository) {
$this->collectionRepository = $collectionRepository;
}
/**
* Returns a specific collection referenced by uid.
*
* @param integer $uid
* @return mixed
*/
public function render($uid) {
if (NULL !== $uid) {
/** @var \TYPO3\CMS\Core\Collection\AbstractRecordCollection $collection */
$collection = $this->collectionRepository->findByUid($uid);
if (NULL !== $collection) {
return $collection->loadContents();
} else {
return NULL;
}
}
return NULL;
}
}