GetPreferenceViewHelper.php 1.8 KB

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