MrmBeCmPodcastPreviewRenderer.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Meramo\mrm_be\Hooks\PageLayoutView;
  3. use \TYPO3\CMS\Core\Utility\GeneralUtility;
  4. use \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
  5. use \TYPO3\CMS\Backend\View\PageLayoutView;
  6. use \TYPO3\CMS\Core\Service\FlexFormService;
  7. use \TYPO3\CMS\Extbase\Utility\LocalizationUtility;
  8. /**
  9. * Contains a preview rendering for the page module for CTYPE="mrm_be_cm_podcast"
  10. */
  11. class MrmBeCmPodcastPreviewRenderer implements PageLayoutViewDrawItemHookInterface
  12. {
  13. /**
  14. * Preprocesses the preview rendering of a content element of type "My new content element"
  15. *
  16. * @param \TYPO3\CMS\Backend\View\PageLayoutView $parentObject Calling parent object
  17. * @param bool $drawItem Whether to draw the item using the default functionality
  18. * @param string $headerContent Header content
  19. * @param string $itemContent Item content
  20. * @param array $row Record row of tt_content
  21. * @return void
  22. */
  23. public function preProcess(
  24. PageLayoutView &$parentObject,
  25. &$drawItem,
  26. &$headerContent,
  27. &$itemContent,
  28. array &$row
  29. )
  30. {
  31. if($row['CType'] === 'mrm_be_cm_podcast') {
  32. // Hier wird das aussehen der oben angezeigt Komponent festgelegt
  33. $headerContent = '<b>' . LocalizationUtility::translate('LLL:EXT:mrm_be/Resources/Private/Language/locallang_ttc.xlf:'.$row['CType'].'.title', '').'</b>';
  34. $ffs = GeneralUtility::makeInstance(FlexFormService::class);
  35. $flex = $ffs->convertFlexFormContentToArray($row['pi_flexform']);
  36. $media = [];
  37. if($flex['media'] == '1') {
  38. $fileRepository = GeneralUtility::makeInstance('TYPO3\CMS\Core\Resource\FileRepository');
  39. $fileObjects = $fileRepository->findByRelation('tt_content', 'media', $row['uid']);
  40. if($fileObjects && sizeOf($fileObjects) >= 1){
  41. $media = array(
  42. 'reference' => $fileObjects[0]->getReferenceProperties(),
  43. 'original' => $fileObjects[0]->getOriginalFile()->getProperties(),
  44. 'resource' => $fileObjects[0]
  45. );
  46. }
  47. }
  48. //console_log($media);
  49. $media = $media['original']['name'];
  50. $transcript = $flex['transcript'];
  51. $itemContent .= '<div><div style="display: flex;"><img src="/typo3conf/ext/mrm_be/Resources/Public/Icons/'.$row['CType'].'.svg" style="width: 32px; height: 32px; margin-right: 6px;"><div style="min-width: 0;"><strong>'.LocalizationUtility::translate('LLL:EXT:mrm_be/Resources/Private/Language/locallang_ttc.xlf:'.$row['CType'].'.title', '').':</strong><br/>'.$media.'</div></div><div>'.$transcript.'</div></div>';
  52. $drawItem = false;
  53. }
  54. }
  55. }