-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDataViewHelper.php
87 lines (81 loc) · 2.54 KB
/
DataViewHelper.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
declare(strict_types=1);
namespace Xima\XimaTypo3FrontendEdit\ViewHelpers;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* This ViewHelper generates a hidden input element which holds data values for the frontend edit dropdown menu.
* You need either provide an uid and a table for the corresponding edit link or an external url.
* The output will only be rendered if the frontend edit is enabled.
*
* Usages:
* ```html
* <xtfe:data label="News Title" uid="12" table="tx_news_domain_model_news" icon="content-news" />
* ```
*
* Output:
* ```html
* <input type="hidden" class="xima-typo3-frontend-edit--data" value="{"label": "News Title", "uid": 12, "table": "tx_news_domain_model_news", "icon": "content-news"}" />
* ```
*/
class DataViewHelper extends AbstractViewHelper
{
/**
* @var bool
*/
protected $escapeOutput = false;
public function initializeArguments(): void
{
$this->registerArgument(
'label',
'string',
'Label for data entry',
true
);
$this->registerArgument(
'uid',
'integer',
'UID of data entry',
);
$this->registerArgument(
'table',
'integer',
'Table of data entry, e.g. tx_news_domain_model_news',
);
$this->registerArgument(
'url',
'string',
'External edit url of data entry',
);
$this->registerArgument(
'icon',
'string',
'Icon identifier for data entry',
);
$this->registerArgument(
'class',
'string',
'Additional class for the hidden input element',
false,
''
);
}
public function render()
{
if (!$GLOBALS['BE_USER'] || (array_key_exists('tx_ximatypo3frontendedit_disable', $GLOBALS['BE_USER']->user) && $GLOBALS['BE_USER']->user['tx_ximatypo3frontendedit_disable'])) {
return '';
}
if (empty($this->arguments['uid']) && empty($this->arguments['url'])) {
return '';
}
$dataAttributes = [];
$class = '';
foreach ($this->arguments as $key => $value) {
if ($key === 'class') {
$class = $value;
} else {
$dataAttributes[$key] = $value;
}
}
return sprintf('<input type="hidden" class="xima-typo3-frontend-edit--data %s" value="%s" />', $class, htmlentities(json_encode($dataAttributes), ENT_QUOTES));
}
}