AbsoluteUrlViewHelper.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\Utilities;
  3. use Closure;
  4. use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
  5. use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
  6. /**
  7. * Make sure the given url is an absolute one by prepending the 'https' prefix
  8. *
  9. * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  10. *
  11. * {ot:utilities.absoluteUrl(url: url)}
  12. *
  13. * @package Opentalent\OtTemplating\ViewHelpers
  14. */
  15. class AbsoluteUrlViewHelper extends OtAbstractViewHelper {
  16. /**
  17. * -- This method is expected by Fluid --
  18. * Declares the viewhelper's parameters
  19. */
  20. public function initializeArguments()
  21. {
  22. $this->registerArgument('url',
  23. 'string',
  24. "An URL",
  25. true);
  26. }
  27. /**
  28. * -- This method is expected by Fluid --
  29. * Renders the content as html
  30. *
  31. * @param array $arguments
  32. * @param Closure $renderChildrenClosure
  33. * @param RenderingContextInterface $renderingContext
  34. * @return string|null
  35. */
  36. public static function renderStatic(
  37. array $arguments,
  38. Closure $renderChildrenClosure,
  39. RenderingContextInterface $renderingContext
  40. ) {
  41. $url = $arguments['url'];
  42. return $url ?
  43. 'https://' . preg_replace("/(?:https?:\/\/)?(.*)/", "$1", $url) :
  44. null;
  45. }
  46. }