GetPreferenceViewHelper.php 1.5 KB

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