TYPO3 CMS  TYPO3_8-7
ElementBrowser.php
Go to the documentation of this file.
1 <?php
2 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 
21 
27 {
33  public function render()
34  {
35  $table = $this->data['tableName'];
36  $fieldName = $this->data['fieldName'];
37  $parameterArray = $this->data['parameterArray'];
38  $elementName = $parameterArray['itemFormElName'];
39  $config = $parameterArray['fieldConf']['config'];
40  $internalType = (string)$config['internal_type'];
41  $allowed = GeneralUtility::trimExplode(',', $config['allowed'], true);
42 
43  if (isset($config['readOnly']) && $config['readOnly']) {
44  return [];
45  }
46 
47  if ($internalType === 'db') {
48  $title = 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.browse_db';
49  } else {
50  $title = 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.browse_file';
51  }
52 
53  // Check against inline uniqueness - Create some onclick js for delete control and element browser
54  // to override record selection in some FAL scenarios - See 'appearance' docs of group element
55  $inlineStackProcessor = GeneralUtility::makeInstance(InlineStackProcessor::class);
56  $inlineStackProcessor->initializeByGivenStructure($this->data['inlineStructure']);
57  $elementBrowserOnClickInline = '';
58  if ($this->data['isInlineChild']
59  && $this->data['inlineParentUid']
60  && $this->data['inlineParentConfig']['foreign_table'] === $table
61  && $this->data['inlineParentConfig']['foreign_unique'] === $fieldName
62  ) {
63  $objectPrefix = $inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid']) . '-' . $table;
64  $elementBrowserOnClickInline = $objectPrefix . '|inline.checkUniqueElement|inline.setUniqueElement';
65  }
66  $elementBrowserType = $internalType;
67  if (is_array($config['appearance']) && isset($config['appearance']['elementBrowserType'])) {
68  $elementBrowserType = $config['appearance']['elementBrowserType'];
69  }
70  $elementBrowserAllowed = implode(',', $allowed);
71  if (is_array($config['appearance']) && isset($config['appearance']['elementBrowserAllowed'])) {
72  $elementBrowserAllowed = $config['appearance']['elementBrowserAllowed'];
73  }
74  $elementBrowserOnClick = 'setFormValueOpenBrowser('
75  . GeneralUtility::quoteJSvalue($elementBrowserType) . ','
76  . GeneralUtility::quoteJSvalue($elementName . '|||' . $elementBrowserAllowed . '|' . $elementBrowserOnClickInline)
77  . ');'
78  . ' return false;';
79 
80  return [
81  'iconIdentifier' => 'actions-insert-record',
82  'title' => $title,
83  'linkAttributes' => [
84  'onClick' => $elementBrowserOnClick,
85  ],
86  ];
87  }
88 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static makeInstance($className,... $constructorArguments)