Advertisement
Guest User

Untitled

a guest
Jan 28th, 2019
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. /**
  2. * FileTeaserImageViewHelper
  3. */
  4. class FileTeaserImageViewHelper extends AbstractViewHelper
  5. {
  6. use CompileWithRenderStatic;
  7. /**
  8. * @var bool
  9. */
  10. protected $escapeOutput = false;
  11. /**
  12. * Initialize arguments.
  13. *
  14. * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
  15. */
  16. public function initializeArguments()
  17. {
  18. parent::initializeArguments();
  19. $this->registerArgument('file', 'array', 'File', true);
  20. $this->registerArgument('as', 'string', 'Name of variable to create', false, 'items');
  21. }
  22. /**
  23. * @param array $arguments
  24. * @param \Closure $renderChildrenClosure
  25. * @param RenderingContextInterface $renderingContext
  26. * @return string
  27. */
  28. public static function renderStatic(
  29. array $arguments,
  30. \Closure $renderChildrenClosure,
  31. RenderingContextInterface $renderingContext
  32. ) {
  33. $variableProvider = $renderingContext->getVariableProvider();
  34.  
  35. if (is_array($arguments['file']) && $arguments['file']['uid']) {
  36.  
  37. if($arguments['file']['sys_language_uid'] > 0 && $arguments['file']['l10n_parent'] > 0) {
  38. $languageUID = $arguments['file']['sys_language_uid'];
  39. } else {
  40. $languageUID = 0;
  41. }
  42.  
  43. $subqueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_metadata');
  44. $subquery = $subqueryBuilder
  45. ->select('*')
  46. ->from('sys_file_metadata')
  47. ->where(
  48. $subqueryBuilder->expr()->eq('file', $arguments['file']['file'])
  49. )
  50. ->andWhere(
  51. $subqueryBuilder->expr()->eq('sys_language_uid', $languageUID)
  52. )
  53. ->execute()->fetchAll();
  54.  
  55. $fileRepository = GeneralUtility::makeInstance(FileRepository::class);
  56. $items = $fileRepository->findByRelation(
  57. 'sys_file_metadata',
  58. 'image',
  59. $subquery[0]['uid']
  60. );
  61.  
  62. } else {
  63. $items = null;
  64. }
  65.  
  66. $variableProvider->add($arguments['as'], $items);
  67. $content = $renderChildrenClosure();
  68. $variableProvider->remove($arguments['as']);
  69.  
  70. return $content;
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement