GetPreferenceViewHelper.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\Template;
  3. use Closure;
  4. use Opentalent\OtCore\Exception\NoSuchWebsiteException;
  5. use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
  6. use Opentalent\OtCore\Website\OtWebsiteRepository;
  7. use Opentalent\OtTemplating\Templating\TemplateRepository;
  8. use TYPO3\CMS\Core\Utility\GeneralUtility;
  9. use TYPO3\CMS\Extbase\Object\ObjectManager;
  10. use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
  11. /**
  12. * Returns the value of the requested preference
  13. *
  14. * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  15. *
  16. * {ot:template.preference('themeColor')}
  17. *
  18. * @package Opentalent\OtTemplating\ViewHelpers\Template
  19. */
  20. class GetPreferenceViewHelper extends OtAbstractViewHelper
  21. {
  22. public function __construct(
  23. private readonly OtWebsiteRepository $otWebsiteRepository,
  24. private readonly TemplateRepository $templateRepository,
  25. ) {}
  26. /**
  27. * -- This method is expected by Fluid --
  28. * Declares the viewhelper's parameters
  29. */
  30. public function initializeArguments()
  31. {
  32. $this->registerArgument(
  33. 'key',
  34. 'string',
  35. 'The name of the requested preference',
  36. true
  37. );
  38. }
  39. /**
  40. * -- This method is expected by Fluid --
  41. * Renders the content as html
  42. *
  43. * @return array
  44. * @throws NoSuchWebsiteException
  45. */
  46. public function render(): array
  47. {
  48. $website = $this->otWebsiteRepository->getCurrentWebsiteFromFEGlobals();
  49. $preferences = $this->templateRepository->getTemplatePreferences($website);
  50. $key = $this->arguments['key'];
  51. return $preferences[$key];
  52. }
  53. }