MatomoSiteIdViewHelper.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Opentalent\OtStats\ViewHelpers;
  3. use Closure;
  4. use Opentalent\OtCore\Page\OtPageRepository;
  5. use Opentalent\OtStats\Settings\StatsSettingsRepository;
  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 current site matomo's id if any, null else
  11. *
  12. * {namespace st=Opentalent\OtStats\ViewHelpers}
  13. *
  14. * {st:matomoSiteId(slug: 'foo')}
  15. *
  16. * @package Opentalent\OtTemplating\ViewHelpers
  17. */
  18. class MatomoSiteIdViewHelper extends AbstractViewHelper
  19. {
  20. /**
  21. * -- This method is expected by Fluid --
  22. * Renders the content as html
  23. *
  24. * @param array $arguments
  25. * @param Closure $renderChildrenClosure
  26. * @param RenderingContextInterface $renderingContext
  27. * @return int|null
  28. */
  29. public static function renderStatic(
  30. array $arguments,
  31. Closure $renderChildrenClosure,
  32. RenderingContextInterface $renderingContext
  33. ) {
  34. $otPageRepository = GeneralUtility::makeInstance(OtPageRepository::class);
  35. $rootPageUid = $otPageRepository->getCurrentSiteRootPageId();
  36. $statsSettingsRepository = GeneralUtility::makeInstance(StatsSettingsRepository::class);
  37. return $statsSettingsRepository->getMatomoSiteId($rootPageUid);
  38. }
  39. }