GetPreferenceViewHelper.php 1.7 KB

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