GetArgumentViewHelper.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. * Check if an argument with this name was passed trough the request.
  8. * If this is the case, returns this argument's value; if not returns null.
  9. *
  10. * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  11. *
  12. * {ot:request.getArgument('name')}
  13. *
  14. * @package Opentalent\OtTemplating\ViewHelpers
  15. */
  16. class GetArgumentViewHelper 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('argument',
  24. 'string',
  25. "The argument'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. $argument = $arguments['argument'];
  43. if (isset($_REQUEST[$argument])) {
  44. return $_REQUEST[$argument];
  45. }
  46. return null;
  47. }
  48. }