/
DummyTextViewHelper.php
48 lines (44 loc) · 1.23 KB
/
DummyTextViewHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* DummyText ViewHelper
*
* @package EXT:simpleblog
* @author Michael Schams <michael@example.com>
* @link https://www.extbase-book.org
*/
namespace ExtbaseBook\Simpleblog\ViewHelpers;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* DummyText ViewHelper class
*/
class DummyTextViewHelper extends AbstractViewHelper
{
/**
* Initialize arguments
*/
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('length', 'int', 'Length of the dummy text');
}
/**
* Render
*
* @param array
* @param \Closure
* @param RenderingContextInterface
* @return string
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
): string {
$length = intval($arguments['length'] ?: 100);
$dummytext = $renderChildrenClosure() ?: 'Lorem ipsum dolor sit amet.';
$repeat = ceil($length / strlen($dummytext));
$content = substr(str_repeat($dummytext . ' ', $repeat), 0, $length) . '.';
return $content;
}
}