/
UniqIdViewHelper.php
65 lines (59 loc) · 1.69 KB
/
UniqIdViewHelper.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace FluidTYPO3\Vhs\ViewHelpers\System;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* ### System: Unique ID
*
* Returns a unique ID based on PHP's uniqid-function.
*
* Comes in useful when handling/generating html-element-IDs
* for usage with JavaScript.
*/
class UniqIdViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;
/**
* @var boolean
*/
protected $escapeOutput = false;
public function initializeArguments(): void
{
$this->registerArgument(
'prefix',
'string',
'An optional prefix for making sure it\'s unique across environments',
false,
''
);
$this->registerArgument(
'moreEntropy',
'boolean',
'Add some pseudo random strings. Refer to uniqid()\'s Reference.',
false,
false
);
}
/**
* @return mixed
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
/** @var string $prefix */
$prefix = $arguments['prefix'];
/** @var boolean $moreEntropy */
$moreEntropy = $arguments['moreEntropy'];
$uniqueId = uniqid($prefix, $moreEntropy);
return $uniqueId;
}
}