GetParameterViewHelper.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\Request;
  3. use Closure;
  4. use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
  5. use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
  6. /**
  7. * Checks if a parameter with this name was passed trough the GET request.
  8. * If this is the case, returns this parameter; if not returns null.
  9. *
  10. * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  11. *
  12. * {ot:request.getParameter('name')}
  13. *
  14. * @package Opentalent\OtTemplating\ViewHelpers
  15. */
  16. class GetParameterViewHelper extends AbstractViewHelper {
  17. /**
  18. * -- This method is expected by Fluid --
  19. * Declares the viewhelper's parameters
  20. */
  21. public function initializeArguments()
  22. {
  23. $this->registerArgument('param',
  24. 'string',
  25. "The parameter's name",
  26. true);
  27. }
  28. /**
  29. * -- This method is expected by Fluid --
  30. * Renders the content as html
  31. *
  32. * @param array $arguments
  33. * @param Closure $renderChildrenClosure
  34. * @param RenderingContextInterface $renderingContext
  35. * @return string|null
  36. */
  37. public static function renderStatic(
  38. array $arguments,
  39. Closure $renderChildrenClosure,
  40. RenderingContextInterface $renderingContext
  41. ) {
  42. $param = $arguments['param'];
  43. if (isset($_REQUEST[$param])) {
  44. return $_REQUEST[$param];
  45. }
  46. return null;
  47. }
  48. }