CountViewHelper.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. * Returns the number of elements of an array
  8. *
  9. * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  10. *
  11. * {ot:utilities.count('{k: v}')}
  12. *
  13. * @package Opentalent\OtTemplating\ViewHelpers
  14. */
  15. class CountViewHelper 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('array',
  23. 'array',
  24. "The array",
  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. $array = $arguments['array'];
  42. return count($array);
  43. }
  44. }