GetPreferenceViewHelper.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\Template;
  3. use Closure;
  4. use Opentalent\OtTemplating\Utilities\OtPageRepository;
  5. use Opentalent\OtTemplating\ViewHelpers\RootPage\GetIdViewHelper;
  6. use TYPO3\CMS\Core\Utility\GeneralUtility;
  7. use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
  8. use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
  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 AbstractViewHelper
  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. if (TYPO3_MODE == 'FE') {
  48. $pageUid = (int) $GLOBALS['TSFE']->id;
  49. } else {
  50. $pageUid = (int) GeneralUtility::_GP('id');
  51. }
  52. $pageRepository = new OtPageRepository();
  53. $preferences = $pageRepository->getTemplatePreferences($pageUid);
  54. $key = $arguments['key'];
  55. return $preferences[$key];
  56. }
  57. }