MatomoSiteIdViewHelper.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace Opentalent\OtStats\ViewHelpers;
  3. use Closure;
  4. use Opentalent\OtCore\Exception\NoSuchWebsiteException;
  5. use Opentalent\OtCore\Website\OtWebsiteRepository;
  6. use TYPO3\CMS\Core\Utility\GeneralUtility;
  7. use TYPO3\CMS\Extbase\Object\ObjectManager;
  8. use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
  9. use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
  10. /**
  11. * Returns the current site matomo's id if any, null else
  12. *
  13. * {namespace st=Opentalent\OtStats\ViewHelpers}
  14. *
  15. * {st:matomoSiteId(slug: 'foo')}
  16. *
  17. * @package Opentalent\OtTemplating\ViewHelpers
  18. */
  19. class MatomoSiteIdViewHelper extends AbstractViewHelper
  20. {
  21. public function __construct(
  22. private readonly OtWebsiteRepository $otWebsiteRepository,
  23. ) {}
  24. /**
  25. * -- This method is expected by Fluid --
  26. * Renders the content as html
  27. *
  28. * @return int|null
  29. * @throws NoSuchWebsiteException
  30. */
  31. public function render(): ?int
  32. {
  33. $website = $this->otWebsiteRepository->getCurrentWebsiteFromFEGlobals();
  34. return $website['matomo_site_id'];
  35. }
  36. }