|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU General Public License version 3 or later. |
|
8
|
|
|
* For the full copyright and license information, please read the |
|
9
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Kitodo\Dlf\ViewHelpers; |
|
13
|
|
|
|
|
14
|
|
|
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; |
|
15
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; |
|
16
|
|
|
use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser; |
|
17
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Viewhelper to parse TypoScript that is used to declare wrapping of metadata |
|
21
|
|
|
* fields and stores the result into a Fluid variable. |
|
22
|
|
|
* |
|
23
|
|
|
* The TypoScript should be passed as child and may contain stdWrap information |
|
24
|
|
|
* for: |
|
25
|
|
|
* - `key`: Used to wrap the metadata label |
|
26
|
|
|
* - `value`: Used to wrap the metadata value |
|
27
|
|
|
* - `all`: Used to wrap the full metadata line (after wrapping key and value) |
|
28
|
|
|
* |
|
29
|
|
|
* The name of the injected variable is passed as parameter. |
|
30
|
|
|
* |
|
31
|
|
|
* Example usage: |
|
32
|
|
|
* |
|
33
|
|
|
* :: |
|
34
|
|
|
* |
|
35
|
|
|
* {typoscript -> kitodo:metadataWrapVariable(name: 'wrapInfo')} |
|
36
|
|
|
* |
|
37
|
|
|
*/ |
|
38
|
|
|
class MetadataWrapVariableViewHelper extends AbstractViewHelper |
|
39
|
|
|
{ |
|
40
|
|
|
/** |
|
41
|
|
|
* @return void |
|
42
|
|
|
*/ |
|
43
|
|
|
public function initializeArguments() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->registerArgument('name', 'string', 'Name of variable to create', true); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param array $arguments |
|
50
|
|
|
* @param \Closure $renderChildrenClosure |
|
51
|
|
|
* @param RenderingContextInterface $renderingContext |
|
52
|
|
|
* @return null |
|
53
|
|
|
*/ |
|
54
|
|
|
public static function renderStatic( |
|
55
|
|
|
array $arguments, |
|
56
|
|
|
\Closure $renderChildrenClosure, |
|
57
|
|
|
RenderingContextInterface $renderingContext |
|
58
|
|
|
) { |
|
59
|
|
|
$parser = GeneralUtility::makeInstance(TypoScriptParser::class); |
|
60
|
|
|
$parser->parse($renderChildrenClosure()); |
|
61
|
|
|
$wrap = [ |
|
62
|
|
|
'key' => $parser->setup['key.'], |
|
63
|
|
|
'value' => $parser->setup['value.'], |
|
64
|
|
|
'all' => $parser->setup['all.'], |
|
65
|
|
|
]; |
|
66
|
|
|
$renderingContext->getVariableProvider()->add($arguments['name'], $wrap); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|