MrmBeCmRawimagePreviewRenderer.php 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace Meramo\mrm_be\Hooks\PageLayoutView;
  3. /*
  4. * This file is part of the TYPO3 CMS project.
  5. *
  6. * It is free software; you can redistribute it and/or modify it under
  7. * the terms of the GNU General Public License, either version 2
  8. * of the License, or any later version.
  9. *
  10. * For the full copyright and license information, please read the
  11. * LICENSE.txt file that was distributed with this source code.
  12. *
  13. * The TYPO3 project - inspiring people to share!
  14. */
  15. use \TYPO3\CMS\Core\Utility\GeneralUtility;
  16. use \TYPO3\CMS\Core\Service\FlexFormService;
  17. use \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
  18. use \TYPO3\CMS\Backend\View\PageLayoutView;
  19. /**
  20. * Contains a preview rendering for the page module of CType="mrm_be_cm_introtext"
  21. */
  22. class MrmBeCmRawimagePreviewRenderer implements PageLayoutViewDrawItemHookInterface
  23. {
  24. /**
  25. * Preprocesses the preview rendering of a content element of type "My new content element"
  26. *
  27. * @param \TYPO3\CMS\Backend\View\PageLayoutView $parentObject Calling parent object
  28. * @param bool $drawItem Whether to draw the item using the default functionality
  29. * @param string $headerContent Header content
  30. * @param string $itemContent Item content
  31. * @param array $row Record row of tt_content
  32. *
  33. * @return void
  34. */
  35. public function preProcess(
  36. PageLayoutView &$parentObject,
  37. &$drawItem,
  38. &$headerContent,
  39. &$itemContent,
  40. array &$row
  41. )
  42. {
  43. if ($row['CType'] === 'mrm_be_cm_rawimage') {
  44. $headerContent = '<b>'.\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:mrm_be/Resources/Private/Language/locallang_ttc.xlf:'.$row['CType'].'.title', '').'</b>';
  45. $ffs = GeneralUtility::makeInstance(FlexFormService::class);
  46. $flex = $ffs->convertFlexFormContentToArray($row['pi_flexform']);
  47. $img = '';
  48. //file_put_contents('/var/www/html/typo3temp/debug.log', json_encode($flex, JSON_PRETTY_PRINT).PHP_EOL, FILE_APPEND);
  49. if($flex['image'] == "1"){
  50. $fileRepository = GeneralUtility::makeInstance('TYPO3\CMS\Core\Resource\FileRepository');
  51. $fileObjects = $fileRepository->findByRelation('tt_content', 'image', $row['uid']);
  52. if($fileObjects && sizeOf($fileObjects) >= 1){
  53. $img = array(
  54. 'reference' => $fileObjects[0]->getReferenceProperties(),
  55. 'original' => $fileObjects[0]->getOriginalFile()->getProperties(),
  56. 'resource' => $fileObjects[0]
  57. );
  58. }
  59. $params = '{"fileId":'.$img['original']['uid'].',"configuration":{"width":64,"height":"64c","crop":{},"_context":"Image.CropScaleMask"}}';
  60. $thumbnailUrl = \TYPO3\CMS\Backend\Utility\BackendUtility::getThumbnailUrl($img["original"]["uid"], ["width" => 64, "height" => "64c", "crop" => [], "_context" => "Image.CropScaleMask"]);
  61. $img = '<img src="'.$thumbnailUrl.'" width="64" height="64"/><em style="white-space:nowrap; overflow:hidden;text-overflow: ellipsis;">'.$img['original']['name'].'</em>';
  62. }
  63. $itemContent .= '<div style="display: flex; flex-direction: row; justify-content: flex-start;"><img src="/typo3conf/ext/mrm_be/Resources/Public/Icons/'.$row['CType'].'.svg" style="width: 32px; height: 32px; margin-right: 6px;"><div style="display: flex; flex-direction: column; min-width: 0;"><strong>'.\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:mrm_be/Resources/Private/Language/locallang_ttc.xlf:'.$row['CType'].'.title', '').':</strong>'.$img.'</div></div>';
  64. $drawItem = false;
  65. /* *
  66. file_put_contents('/var/www/html/typo3temp/debug.log', $itemContent.PHP_EOL, FILE_APPEND);
  67. file_put_contents('/var/www/html/typo3temp/debug.log', json_encode($flex, JSON_PRETTY_PRINT).PHP_EOL, FILE_APPEND);
  68. file_put_contents('/var/www/html/typo3temp/debug.log', '----'.PHP_EOL, FILE_APPEND);
  69. /* */
  70. }
  71. }
  72. }