|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the TYPO3 CMS project. |
|
7
|
|
|
* |
|
8
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
9
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
10
|
|
|
* of the License, or any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* For the full copyright and license information, please read the |
|
13
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
14
|
|
|
* |
|
15
|
|
|
* The TYPO3 project - inspiring people to share! |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace TYPO3\CMS\Backend\Form\FieldControl; |
|
19
|
|
|
|
|
20
|
|
|
use TYPO3\CMS\Backend\Form\AbstractNode; |
|
21
|
|
|
use TYPO3\CMS\Backend\Form\InlineStackProcessor; |
|
22
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Renders the icon "select element via element browser", |
|
26
|
|
|
* typically used for type=group. |
|
27
|
|
|
*/ |
|
28
|
|
|
class ElementBrowser extends AbstractNode |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Add button control |
|
32
|
|
|
* |
|
33
|
|
|
* @return array As defined by FieldControl class |
|
34
|
|
|
*/ |
|
35
|
|
|
public function render() |
|
36
|
|
|
{ |
|
37
|
|
|
$table = $this->data['tableName']; |
|
38
|
|
|
$fieldName = $this->data['fieldName']; |
|
39
|
|
|
$parameterArray = $this->data['parameterArray']; |
|
40
|
|
|
$elementName = $parameterArray['itemFormElName']; |
|
41
|
|
|
$config = $parameterArray['fieldConf']['config']; |
|
42
|
|
|
$internalType = (string)$config['internal_type']; |
|
43
|
|
|
$allowed = $config['allowed']; |
|
44
|
|
|
|
|
45
|
|
|
if (isset($config['readOnly']) && $config['readOnly']) { |
|
46
|
|
|
return []; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if ($internalType === 'db') { |
|
50
|
|
|
$title = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.browse_db'; |
|
51
|
|
|
} else { |
|
52
|
|
|
$title = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.browse_file'; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
// Check against inline uniqueness - Create some onclick js for delete control and element browser |
|
56
|
|
|
// to override record selection in some FAL scenarios - See 'appearance' docs of group element |
|
57
|
|
|
$inlineStackProcessor = GeneralUtility::makeInstance(InlineStackProcessor::class); |
|
58
|
|
|
$inlineStackProcessor->initializeByGivenStructure($this->data['inlineStructure']); |
|
59
|
|
|
$elementBrowserOnClickInline = ''; |
|
60
|
|
|
if ($this->data['isInlineChild'] |
|
61
|
|
|
&& $this->data['inlineParentUid'] |
|
62
|
|
|
&& $this->data['inlineParentConfig']['foreign_table'] === $table |
|
63
|
|
|
&& $this->data['inlineParentConfig']['foreign_unique'] === $fieldName |
|
64
|
|
|
) { |
|
65
|
|
|
$objectPrefix = $inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid']) . '-' . $table; |
|
66
|
|
|
$elementBrowserOnClickInline = $objectPrefix; |
|
67
|
|
|
} |
|
68
|
|
|
$elementBrowserType = $internalType; |
|
69
|
|
|
if (is_array($config['appearance'] ?? null)) { |
|
70
|
|
|
if (isset($config['appearance']['elementBrowserType'])) { |
|
71
|
|
|
$elementBrowserType = $config['appearance']['elementBrowserType']; |
|
72
|
|
|
} |
|
73
|
|
|
if (isset($config['appearance']['elementBrowserAllowed'])) { |
|
74
|
|
|
$allowed = $config['appearance']['elementBrowserAllowed']; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
// Remove any white-spaces from the allowed extension lists |
|
78
|
|
|
$elementBrowserAllowed = implode(',', GeneralUtility::trimExplode(',', $allowed, true)); |
|
79
|
|
|
|
|
80
|
|
|
return [ |
|
81
|
|
|
'iconIdentifier' => 'actions-insert-record', |
|
82
|
|
|
'title' => $title, |
|
83
|
|
|
'linkAttributes' => [ |
|
84
|
|
|
'class' => 't3js-element-browser', |
|
85
|
|
|
'data-mode' => htmlspecialchars($elementBrowserType), |
|
86
|
|
|
'data-params' => htmlspecialchars($elementName . '|||' . $elementBrowserAllowed . '|' . $elementBrowserOnClickInline) |
|
87
|
|
|
], |
|
88
|
|
|
]; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|