GetPreferenceViewHelper.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. $templateRepository = GeneralUtility::makeInstance(TemplateRepository::class);
  48. $preferences = $templateRepository->getTemplatePreferences();
  49. $key = $arguments['key'];
  50. return $preferences[$key];
  51. }
  52. }