MrmBeCmChatbotPreviewRenderer.php 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_paragraph"
  21. */
  22. class MrmBeCmChatbotPreviewRenderer 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. if ($row['CType'] === 'mrm_be_cm_chatbot') {
  43. $headerContent = '<b>' . \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:mrm_be/Resources/Private/Language/locallang_ttc.xlf:' . $row['CType'] . '.title', '') . '</b>';
  44. $ffs = GeneralUtility::makeInstance(FlexFormService::class);
  45. $flex = $ffs->convertFlexFormContentToArray($row['pi_flexform']);
  46. $terms = strip_tags($flex['settings']['terms']);
  47. $type = strip_tags($flex['settings']['type']) ?? '';
  48. $category = strip_tags($flex['settings']['category']) ?? '';
  49. $url = strip_tags($flex['settings']['url']) ?? '';
  50. $itemContent = '<div style="display: flex; flec-direction: row; justify-content: flex-start;">';
  51. $itemContent .= '<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><br>';
  52. $itemContent .= '<strong>' . \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:mrm_be/Resources/Private/Language/locallang_ttc.xlf:' . $row['CType'] . '.terms', '') . ':</strong><em style="white-space:nowrap; overflow:hidden;text-overflow: ellipsis;">' . $terms . '</em></strong><br>';
  53. $itemContent .= '<strong>' . \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:mrm_be/Resources/Private/Language/locallang_ttc.xlf:' . $row['CType'] . '.type', '') . ':</strong><em style="white-space:nowrap; overflow:hidden;text-overflow: ellipsis;">' . $type . '</em></strong><br>';
  54. $itemContent .= '<strong>' . \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:mrm_be/Resources/Private/Language/locallang_ttc.xlf:' . $row['CType'] . '.category', '') . ':</strong><em style="white-space:nowrap; overflow:hidden;text-overflow: ellipsis;">' . $category . '</em></strong><br>';
  55. $itemContent .= '<strong>' . \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:mrm_be/Resources/Private/Language/locallang_ttc.xlf:' . $row['CType'] . '.url', '') . ':</strong><em style="white-space:nowrap; overflow:hidden;text-overflow: ellipsis;">' . $url . '</em></strong></div>';
  56. $drawItem = false;
  57. }
  58. }
  59. }