Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * FileTeaserImageViewHelper
- */
- class FileTeaserImageViewHelper extends AbstractViewHelper
- {
- use CompileWithRenderStatic;
- /**
- * @var bool
- */
- protected $escapeOutput = false;
- /**
- * Initialize arguments.
- *
- * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
- */
- public function initializeArguments()
- {
- parent::initializeArguments();
- $this->registerArgument('file', 'array', 'File', true);
- $this->registerArgument('as', 'string', 'Name of variable to create', false, 'items');
- }
- /**
- * @param array $arguments
- * @param \Closure $renderChildrenClosure
- * @param RenderingContextInterface $renderingContext
- * @return string
- */
- public static function renderStatic(
- array $arguments,
- \Closure $renderChildrenClosure,
- RenderingContextInterface $renderingContext
- ) {
- $variableProvider = $renderingContext->getVariableProvider();
- if (is_array($arguments['file']) && $arguments['file']['uid']) {
- if($arguments['file']['sys_language_uid'] > 0 && $arguments['file']['l10n_parent'] > 0) {
- $languageUID = $arguments['file']['sys_language_uid'];
- } else {
- $languageUID = 0;
- }
- $subqueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_metadata');
- $subquery = $subqueryBuilder
- ->select('*')
- ->from('sys_file_metadata')
- ->where(
- $subqueryBuilder->expr()->eq('file', $arguments['file']['file'])
- )
- ->andWhere(
- $subqueryBuilder->expr()->eq('sys_language_uid', $languageUID)
- )
- ->execute()->fetchAll();
- $fileRepository = GeneralUtility::makeInstance(FileRepository::class);
- $items = $fileRepository->findByRelation(
- 'sys_file_metadata',
- 'image',
- $subquery[0]['uid']
- );
- } else {
- $items = null;
- }
- $variableProvider->add($arguments['as'], $items);
- $content = $renderChildrenClosure();
- $variableProvider->remove($arguments['as']);
- return $content;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement