Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add CollectionViewHelper #578

Merged
merged 1 commit into from
Aug 13, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions Classes/ViewHelpers/Resource/CollectionViewHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
namespace FluidTYPO3\Vhs\ViewHelpers\Resource;

/***************************************************************
* Copyright notice
*
* (c) 2014 Dmitri Pisarev <dimaip@gmail.com>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

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;
}
}
}
}