Last active
November 7, 2016 14:16
-
-
Save fazzyx/5dcf6448b666d064a69e27a01ceb906a to your computer and use it in GitHub Desktop.
TYPO3 Fluid ViewHelper for content element "shortcut"
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 | |
namespace NAMESPACE\ThemeMgCustom\ViewHelpers; | |
/* | |
* | |
* Copyright notice | |
* | |
* (c) 2015 Claus Fassing <[email protected]>, MEDIENGARAGE | |
* | |
* 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 3 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! | |
*/ | |
/** | |
* <mg:Reference records="{panel.records}" field="header" /> | |
* records = record ids, field = table field | |
* | |
* @author Claus Fassing <[email protected]> | |
*/ | |
class ReferenceViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper | |
{ | |
/** | |
* | |
* @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface | |
*/ | |
protected $configurationManager; | |
/** | |
* | |
* @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer | |
*/ | |
protected $cObj; | |
/** | |
* Inject configuration manager and get content object | |
* | |
* @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager | |
*/ | |
public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager) | |
{ | |
$this->configurationManager = $configurationManager; | |
$this->cObj = $this->configurationManager->getContentObject(); | |
} | |
/** | |
* Get content object of ce type 'shortcut'. Only return the field value | |
* | |
* @param string $records | |
* @param string $field | |
* @return string | |
*/ | |
public function render($records, $field) | |
{ | |
$recordList = explode(',', $records); | |
for($i=0;$i < count($recordList);$i++) { | |
$uids .= end(explode('_', $recordList[$i])); | |
if($i < count($recordList) - 1) { | |
$uids .= ','; | |
} | |
} | |
$conf = array( | |
'table' => 'tt_content', | |
'select.' => array( | |
'pidInList' => '0', | |
'uidInList' => $uids, | |
), | |
'renderObj' => 'COA', | |
'renderObj.' => array( | |
'10' => 'TEXT', | |
'10.' => array( | |
'field' => $field | |
) | |
) | |
); | |
$content = $this->cObj->cObjGetSingle('CONTENT', $conf); | |
return $content; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice ViewHelper, but I would change three things:
The change of the explode function gives more security and the third thing a little more speed.