[CLEANUP] The correct case must be used for standard PHP types in phpdoc
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / Container / InlineControlContainer.php
1 <?php
2 namespace TYPO3\CMS\Backend\Form\Container;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Form\InlineStackProcessor;
18 use TYPO3\CMS\Backend\Form\NodeFactory;
19 use TYPO3\CMS\Backend\Utility\BackendUtility;
20 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
21 use TYPO3\CMS\Core\Imaging\Icon;
22 use TYPO3\CMS\Core\Imaging\IconFactory;
23 use TYPO3\CMS\Core\Resource\Folder;
24 use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry;
25 use TYPO3\CMS\Core\Utility\GeneralUtility;
26 use TYPO3\CMS\Core\Utility\MathUtility;
27 use TYPO3\CMS\Lang\LanguageService;
28
29 /**
30 * Inline element entry container.
31 *
32 * This container is the entry step to rendering an inline element. It is created by SingleFieldContainer.
33 *
34 * The code creates the main structure for the single inline elements, initializes
35 * the inlineData array, that is manipulated and also returned back in its manipulated state.
36 * The "control" stuff of inline elements is rendered here, for example the "create new" button.
37 *
38 * For each existing inline relation an InlineRecordContainer is called for further processing.
39 */
40 class InlineControlContainer extends AbstractContainer
41 {
42 /**
43 * Inline data array used in JS, returned as JSON object to frontend
44 *
45 * @var array
46 */
47 protected $inlineData = [];
48
49 /**
50 * @var InlineStackProcessor
51 */
52 protected $inlineStackProcessor;
53
54 /**
55 * @var IconFactory
56 */
57 protected $iconFactory;
58
59 /**
60 * @var string[]
61 */
62 protected $requireJsModules = [];
63
64 /**
65 * @var array Default wizards
66 */
67 protected $defaultFieldWizard = [
68 'localizationStateSelector' => [
69 'renderType' => 'localizationStateSelector',
70 ],
71 ];
72
73 /**
74 * Container objects give $nodeFactory down to other containers.
75 *
76 * @param NodeFactory $nodeFactory
77 * @param array $data
78 */
79 public function __construct(NodeFactory $nodeFactory, array $data)
80 {
81 parent::__construct($nodeFactory, $data);
82 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
83 }
84
85 /**
86 * Entry method
87 *
88 * @return array As defined in initializeResultArray() of AbstractNode
89 */
90 public function render()
91 {
92 $languageService = $this->getLanguageService();
93
94 $this->inlineData = $this->data['inlineData'];
95
96 /** @var InlineStackProcessor $inlineStackProcessor */
97 $inlineStackProcessor = GeneralUtility::makeInstance(InlineStackProcessor::class);
98 $this->inlineStackProcessor = $inlineStackProcessor;
99 $inlineStackProcessor->initializeByGivenStructure($this->data['inlineStructure']);
100
101 $table = $this->data['tableName'];
102 $row = $this->data['databaseRow'];
103 $field = $this->data['fieldName'];
104 $parameterArray = $this->data['parameterArray'];
105
106 $resultArray = $this->initializeResultArray();
107
108 $config = $parameterArray['fieldConf']['config'];
109 $foreign_table = $config['foreign_table'];
110
111 $language = 0;
112 $languageFieldName = $GLOBALS['TCA'][$table]['ctrl']['languageField'];
113 if (BackendUtility::isTableLocalizable($table)) {
114 $language = isset($row[$languageFieldName][0]) ? (int)$row[$languageFieldName][0] : (int)$row[$languageFieldName];
115 }
116
117 // Add the current inline job to the structure stack
118 $newStructureItem = [
119 'table' => $table,
120 'uid' => $row['uid'],
121 'field' => $field,
122 'config' => $config,
123 'localizationMode' => BackendUtility::getInlineLocalizationMode($table, $config),
124 ];
125 // Extract FlexForm parts (if any) from element name, e.g. array('vDEF', 'lDEF', 'FlexField', 'vDEF')
126 if (!empty($parameterArray['itemFormElName'])) {
127 $flexFormParts = $this->extractFlexFormParts($parameterArray['itemFormElName']);
128 if ($flexFormParts !== null) {
129 $newStructureItem['flexform'] = $flexFormParts;
130 }
131 }
132 $inlineStackProcessor->pushStableStructureItem($newStructureItem);
133
134 // Transport the flexform DS identifier fields to the FormInlineAjaxController
135 if (!empty($newStructureItem['flexform'])
136 && isset($this->data['processedTca']['columns'][$field]['config']['dataStructureIdentifier'])
137 ) {
138 $config['dataStructureIdentifier'] = $this->data['processedTca']['columns'][$field]['config']['dataStructureIdentifier'];
139 }
140
141 // Hand over original returnUrl to FormInlineAjaxController. Needed if opening for instance a
142 // nested element in a new view to then go back to the original returnUrl and not the url of
143 // the inline ajax controller
144 $config['originalReturnUrl'] = $this->data['returnUrl'];
145
146 // e.g. data[<table>][<uid>][<field>]
147 $nameForm = $inlineStackProcessor->getCurrentStructureFormPrefix();
148 // e.g. data-<pid>-<table1>-<uid1>-<field1>-<table2>-<uid2>-<field2>
149 $nameObject = $inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid']);
150
151 $config['inline']['first'] = false;
152 $firstChild = reset($this->data['parameterArray']['fieldConf']['children']);
153 if (isset($firstChild['databaseRow']['uid'])) {
154 $config['inline']['first'] = $firstChild['databaseRow']['uid'];
155 }
156 $config['inline']['last'] = false;
157 $lastChild = end($this->data['parameterArray']['fieldConf']['children']);
158 if (isset($lastChild['databaseRow']['uid'])) {
159 $config['inline']['last'] = $lastChild['databaseRow']['uid'];
160 }
161
162 $top = $inlineStackProcessor->getStructureLevel(0);
163
164 $this->inlineData['config'][$nameObject] = [
165 'table' => $foreign_table,
166 'md5' => md5($nameObject)
167 ];
168 $this->inlineData['config'][$nameObject . '-' . $foreign_table] = [
169 'min' => $config['minitems'],
170 'max' => $config['maxitems'],
171 'sortable' => $config['appearance']['useSortable'],
172 'top' => [
173 'table' => $top['table'],
174 'uid' => $top['uid']
175 ],
176 'context' => [
177 'config' => $config,
178 'hmac' => GeneralUtility::hmac(json_encode($config), 'InlineContext'),
179 ],
180 ];
181 $this->inlineData['nested'][$nameObject] = $this->data['tabAndInlineStack'];
182
183 $uniqueMax = 0;
184 $uniqueIds = [];
185
186 if ($config['foreign_unique']) {
187 // Add inlineData['unique'] with JS unique configuration
188 $type = $config['selectorOrUniqueConfiguration']['config']['type'] === 'select' ? 'select' : 'groupdb';
189 foreach ($parameterArray['fieldConf']['children'] as $child) {
190 // Determine used unique ids, skip not localized records
191 if (!$child['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
192 $value = $child['databaseRow'][$config['foreign_unique']];
193 // We're assuming there is only one connected value here for both select and group
194 if ($type === 'select') {
195 // A resolved select field is an array - take first value
196 $value = $value['0'];
197 } else {
198 // A group field is still a list with pipe separated uid|tableName
199 $valueParts = GeneralUtility::trimExplode('|', $value);
200 $itemParts = explode('_', $valueParts[0]);
201 $value = [
202 'uid' => array_pop($itemParts),
203 'table' => implode('_', $itemParts)
204 ];
205 }
206 // @todo: This is weird, $value has different structure for group and select fields?
207 $uniqueIds[$child['databaseRow']['uid']] = $value;
208 }
209 }
210 $possibleRecords = $config['selectorOrUniquePossibleRecords'];
211 $possibleRecordsUidToTitle = [];
212 foreach ($possibleRecords as $possibleRecord) {
213 $possibleRecordsUidToTitle[$possibleRecord[1]] = $possibleRecord[0];
214 }
215 $uniqueMax = $config['appearance']['useCombination'] || empty($possibleRecords) ? -1 : count($possibleRecords);
216 $this->inlineData['unique'][$nameObject . '-' . $foreign_table] = [
217 'max' => $uniqueMax,
218 'used' => $uniqueIds,
219 'type' => $type,
220 'table' => $foreign_table,
221 'elTable' => $config['selectorOrUniqueConfiguration']['foreignTable'],
222 'field' => $config['foreign_unique'],
223 'selector' => $config['selectorOrUniqueConfiguration']['isSelector'] ? $type : false,
224 'possible' => $possibleRecordsUidToTitle,
225 ];
226 }
227
228 $resultArray['inlineData'] = $this->inlineData;
229
230 // @todo: It might be a good idea to have something like "isLocalizedRecord" or similar set by a data provider
231 $uidOfDefaultRecord = $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']];
232 $isLocalizedParent = $language > 0
233 && ($uidOfDefaultRecord[0] ?? $uidOfDefaultRecord) > 0
234 && MathUtility::canBeInterpretedAsInteger($row['uid']);
235 $numberOfFullLocalizedChildren = 0;
236 $numberOfNotYetLocalizedChildren = 0;
237 foreach ($this->data['parameterArray']['fieldConf']['children'] as $child) {
238 if (!$child['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
239 $numberOfFullLocalizedChildren ++;
240 }
241 if ($isLocalizedParent && $child['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
242 $numberOfNotYetLocalizedChildren ++;
243 }
244 }
245
246 // Render the localization links if needed
247 $localizationLinks = '';
248 if ($numberOfNotYetLocalizedChildren) {
249 // Add the "Localize all records" link before all child records:
250 if (isset($config['appearance']['showAllLocalizationLink']) && $config['appearance']['showAllLocalizationLink']) {
251 $localizationLinks = ' ' . $this->getLevelInteractionLink('localize', $nameObject . '-' . $foreign_table, $config);
252 }
253 // Add the "Synchronize with default language" link before all child records:
254 if (isset($config['appearance']['showSynchronizationLink']) && $config['appearance']['showSynchronizationLink']) {
255 $localizationLinks .= ' ' . $this->getLevelInteractionLink('synchronize', $nameObject . '-' . $foreign_table, $config);
256 }
257 }
258
259 // Define how to show the "Create new record" link - if there are more than maxitems, hide it
260 if ($numberOfFullLocalizedChildren >= $config['maxitems'] || $uniqueMax > 0 && $numberOfFullLocalizedChildren >= $uniqueMax) {
261 $config['inline']['inlineNewButtonStyle'] = 'display: none;';
262 $config['inline']['inlineNewRelationButtonStyle'] = 'display: none;';
263 $config['inline']['inlineOnlineMediaAddButtonStyle'] = 'display: none;';
264 }
265
266 // Render the level links (create new record):
267 $levelLinks = '';
268 if (!empty($config['appearance']['enabledControls']['new'])) {
269 $levelLinks = $this->getLevelInteractionLink('newRecord', $nameObject . '-' . $foreign_table, $config);
270 }
271 // Wrap all inline fields of a record with a <div> (like a container)
272 $html = '<div class="form-group" id="' . $nameObject . '">';
273 // Add the level links before all child records:
274 if ($config['appearance']['levelLinksPosition'] === 'both' || $config['appearance']['levelLinksPosition'] === 'top') {
275 $html .= '<div class="form-group t3js-formengine-validation-marker">' . $levelLinks . $localizationLinks . '</div>';
276 }
277
278 // If it's required to select from possible child records (reusable children), add a selector box
279 if ($config['foreign_selector'] && $config['appearance']['showPossibleRecordsSelector'] !== false) {
280 if ($config['selectorOrUniqueConfiguration']['config']['type'] === 'select') {
281 $selectorBox = $this->renderPossibleRecordsSelectorTypeSelect($config, $uniqueIds);
282 } else {
283 $selectorBox = $this->renderPossibleRecordsSelectorTypeGroupDB($config);
284 }
285 $html .= $selectorBox . $localizationLinks;
286 }
287
288 $title = $languageService->sL(trim($parameterArray['fieldConf']['label']));
289 $html .= '<div class="panel-group panel-hover" data-title="' . htmlspecialchars($title) . '" id="' . $nameObject . '_records">';
290
291 $sortableRecordUids = [];
292 foreach ($this->data['parameterArray']['fieldConf']['children'] as $options) {
293 $options['inlineParentUid'] = $row['uid'];
294 $options['inlineFirstPid'] = $this->data['inlineFirstPid'];
295 // @todo: this can be removed if this container no longer sets additional info to $config
296 $options['inlineParentConfig'] = $config;
297 $options['inlineData'] = $this->inlineData;
298 $options['inlineStructure'] = $inlineStackProcessor->getStructure();
299 $options['inlineExpandCollapseStateArray'] = $this->data['inlineExpandCollapseStateArray'];
300 $options['renderType'] = 'inlineRecordContainer';
301 $childResult = $this->nodeFactory->create($options)->render();
302 $html .= $childResult['html'];
303 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childResult, false);
304 if (!$options['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
305 // Don't add record to list of "valid" uids if it is only the default
306 // language record of a not yet localized child
307 $sortableRecordUids[] = $options['databaseRow']['uid'];
308 }
309 }
310
311 $html .= '</div>';
312
313 $fieldWizardResult = $this->renderFieldWizard();
314 $fieldWizardHtml = $fieldWizardResult['html'];
315 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldWizardResult, false);
316 $html .= $fieldWizardHtml;
317
318 // Add the level links after all child records:
319 if ($config['appearance']['levelLinksPosition'] === 'both' || $config['appearance']['levelLinksPosition'] === 'bottom') {
320 $html .= $levelLinks . $localizationLinks;
321 }
322 if (is_array($config['customControls'])) {
323 $html .= '<div id="' . $nameObject . '_customControls">';
324 foreach ($config['customControls'] as $customControlConfig) {
325 $parameters = [
326 'table' => $table,
327 'field' => $field,
328 'row' => $row,
329 'nameObject' => $nameObject,
330 'nameForm' => $nameForm,
331 'config' => $config
332 ];
333 $html .= GeneralUtility::callUserFunction($customControlConfig, $parameters, $this);
334 }
335 $html .= '</div>';
336 }
337 // Add Drag&Drop functions for sorting to FormEngine::$additionalJS_post
338 if (count($sortableRecordUids) > 1 && $config['appearance']['useSortable']) {
339 $resultArray['additionalJavaScriptPost'][] = 'inline.createDragAndDropSorting("' . $nameObject . '_records' . '");';
340 }
341 $resultArray['requireJsModules'] = array_merge($resultArray['requireJsModules'], $this->requireJsModules);
342
343 // Publish the uids of the child records in the given order to the browser
344 $html .= '<input type="hidden" name="' . $nameForm . '" value="' . implode(',', $sortableRecordUids) . '" '
345 . ' data-formengine-validation-rules="' . htmlspecialchars($this->getValidationDataAsJsonString(['type' => 'inline', 'minitems' => $config['minitems'], 'maxitems' => $config['maxitems']])) . '"'
346 . ' class="inlineRecord" />';
347 // Close the wrap for all inline fields (container)
348 $html .= '</div>';
349
350 $resultArray['html'] = $html;
351 return $resultArray;
352 }
353
354 /**
355 * Creates the HTML code of a general link to be used on a level of inline children.
356 * The possible keys for the parameter $type are 'newRecord', 'localize' and 'synchronize'.
357 *
358 * @param string $type The link type, values are 'newRecord', 'localize' and 'synchronize'.
359 * @param string $objectPrefix The "path" to the child record to create (e.g. 'data-parentPageId-partenTable-parentUid-parentField-childTable]')
360 * @param array $conf TCA configuration of the parent(!) field
361 * @return string The HTML code of the new link, wrapped in a div
362 */
363 protected function getLevelInteractionLink($type, $objectPrefix, $conf = [])
364 {
365 $languageService = $this->getLanguageService();
366 $nameObject = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid']);
367 $attributes = [];
368 switch ($type) {
369 case 'newRecord':
370 $title = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.createnew'));
371 $icon = 'actions-document-new';
372 $className = 'typo3-newRecordLink';
373 $attributes['class'] = 'btn btn-default inlineNewButton ' . $this->inlineData['config'][$nameObject]['md5'];
374 $attributes['onclick'] = 'return inline.createNewRecord(' . GeneralUtility::quoteJSvalue($objectPrefix) . ')';
375 if (!empty($conf['inline']['inlineNewButtonStyle'])) {
376 $attributes['style'] = $conf['inline']['inlineNewButtonStyle'];
377 }
378 if (!empty($conf['appearance']['newRecordLinkAddTitle'])) {
379 $title = htmlspecialchars(sprintf(
380 $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.createnew.link'),
381 $languageService->sL($GLOBALS['TCA'][$conf['foreign_table']]['ctrl']['title'])
382 ));
383 } elseif (isset($conf['appearance']['newRecordLinkTitle']) && $conf['appearance']['newRecordLinkTitle'] !== '') {
384 $title = htmlspecialchars($languageService->sL($conf['appearance']['newRecordLinkTitle']));
385 }
386 break;
387 case 'localize':
388 $title = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:localizeAllRecords'));
389 $icon = 'actions-document-localize';
390 $className = 'typo3-localizationLink';
391 $attributes['class'] = 'btn btn-default';
392 $attributes['onclick'] = 'return inline.synchronizeLocalizeRecords(' . GeneralUtility::quoteJSvalue($objectPrefix) . ', \'localize\')';
393 break;
394 case 'synchronize':
395 $title = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:synchronizeWithOriginalLanguage'));
396 $icon = 'actions-document-synchronize';
397 $className = 'typo3-synchronizationLink';
398 $attributes['class'] = 'btn btn-default inlineNewButton ' . $this->inlineData['config'][$nameObject]['md5'];
399 $attributes['onclick'] = 'return inline.synchronizeLocalizeRecords(' . GeneralUtility::quoteJSvalue($objectPrefix) . ', \'synchronize\')';
400 break;
401 default:
402 $title = '';
403 $icon = '';
404 $className = '';
405 }
406 // Create the link:
407 $icon = $icon ? $this->iconFactory->getIcon($icon, Icon::SIZE_SMALL)->render() : '';
408 $link = $this->wrapWithAnchor($icon . $title, '#', $attributes);
409 return '<div' . ($className ? ' class="' . $className . '"' : '') . 'title="' . $title . '">' . $link . '</div>';
410 }
411
412 /**
413 * Wraps a text with an anchor and returns the HTML representation.
414 *
415 * @param string $text The text to be wrapped by an anchor
416 * @param string $link The link to be used in the anchor
417 * @param array $attributes Array of attributes to be used in the anchor
418 * @return string The wrapped text as HTML representation
419 */
420 protected function wrapWithAnchor($text, $link, $attributes = [])
421 {
422 $link = trim($link);
423 $result = '<a href="' . ($link ?: '#') . '"';
424 foreach ($attributes as $key => $value) {
425 $result .= ' ' . $key . '="' . htmlspecialchars(trim($value)) . '"';
426 }
427 $result .= '>' . $text . '</a>';
428 return $result;
429 }
430
431 /**
432 * Generate a link that opens an element browser in a new window.
433 * For group/db there is no way to use a "selector" like a <select>|</select>-box.
434 *
435 * @param array $inlineConfiguration TCA inline configuration of the parent(!) field
436 * @return string A HTML link that opens an element browser in a new window
437 */
438 protected function renderPossibleRecordsSelectorTypeGroupDB(array $inlineConfiguration)
439 {
440 $backendUser = $this->getBackendUserAuthentication();
441 $languageService = $this->getLanguageService();
442
443 $groupFieldConfiguration = $inlineConfiguration['selectorOrUniqueConfiguration']['config'];
444
445 $foreign_table = $inlineConfiguration['foreign_table'];
446 $allowed = $groupFieldConfiguration['allowed'];
447 $objectPrefix = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid']) . '-' . $foreign_table;
448 $nameObject = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid']);
449 $mode = 'db';
450 $showUpload = false;
451 $elementBrowserEnabled = true;
452 if (!empty($inlineConfiguration['appearance']['createNewRelationLinkTitle'])) {
453 $createNewRelationText = htmlspecialchars($languageService->sL($inlineConfiguration['appearance']['createNewRelationLinkTitle']));
454 } else {
455 $createNewRelationText = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.createNewRelation'));
456 }
457 if (is_array($groupFieldConfiguration['appearance'])) {
458 if (isset($groupFieldConfiguration['appearance']['elementBrowserType'])) {
459 $mode = $groupFieldConfiguration['appearance']['elementBrowserType'];
460 }
461 if ($mode === 'file') {
462 $showUpload = true;
463 }
464 if (isset($inlineConfiguration['appearance']['fileUploadAllowed'])) {
465 $showUpload = (bool)$inlineConfiguration['appearance']['fileUploadAllowed'];
466 }
467 if (isset($groupFieldConfiguration['appearance']['elementBrowserAllowed'])) {
468 $allowed = $groupFieldConfiguration['appearance']['elementBrowserAllowed'];
469 }
470 if (isset($inlineConfiguration['appearance']['elementBrowserEnabled'])) {
471 $elementBrowserEnabled = (bool)$inlineConfiguration['appearance']['elementBrowserEnabled'];
472 }
473 }
474 $browserParams = '|||' . $allowed . '|' . $objectPrefix . '|inline.checkUniqueElement||inline.importElement';
475 $onClick = 'setFormValueOpenBrowser(' . GeneralUtility::quoteJSvalue($mode) . ', ' . GeneralUtility::quoteJSvalue($browserParams) . '); return false;';
476
477 $buttonStyle = '';
478 if (isset($inlineConfiguration['inline']['inlineNewRelationButtonStyle'])) {
479 $buttonStyle = ' style="' . $inlineConfiguration['inline']['inlineNewRelationButtonStyle'] . '"';
480 }
481 $item = '';
482 if ($elementBrowserEnabled) {
483 $item .= '
484 <a href="#" class="btn btn-default inlineNewRelationButton ' . $this->inlineData['config'][$nameObject]['md5'] . '"
485 ' . $buttonStyle . ' onclick="' . htmlspecialchars($onClick) . '" title="' . $createNewRelationText . '">
486 ' . $this->iconFactory->getIcon('actions-insert-record', Icon::SIZE_SMALL)->render() . '
487 ' . $createNewRelationText . '
488 </a>';
489 }
490
491 $isDirectFileUploadEnabled = (bool)$backendUser->uc['edit_docModuleUpload'];
492 $allowedArray = GeneralUtility::trimExplode(',', $allowed, true);
493 $onlineMediaAllowed = OnlineMediaHelperRegistry::getInstance()->getSupportedFileExtensions();
494 if (!empty($allowedArray)) {
495 $onlineMediaAllowed = array_intersect($allowedArray, $onlineMediaAllowed);
496 }
497 if ($showUpload && $isDirectFileUploadEnabled) {
498 $folder = $backendUser->getDefaultUploadFolder(
499 $this->data['parentPageRow']['uid'],
500 $this->data['tableName'],
501 $this->data['fieldName']
502 );
503 if (
504 $folder instanceof Folder
505 && $folder->getStorage()->checkUserActionPermission('add', 'File')
506 ) {
507 $maxFileSize = GeneralUtility::getMaxUploadFileSize() * 1024;
508 $item .= ' <a href="#" class="btn btn-default t3js-drag-uploader inlineNewFileUploadButton ' . $this->inlineData['config'][$nameObject]['md5'] . '"
509 ' . $buttonStyle . '
510 data-dropzone-target="#' . htmlspecialchars($this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid'])) . '"
511 data-insert-dropzone-before="1"
512 data-file-irre-object="' . htmlspecialchars($objectPrefix) . '"
513 data-file-allowed="' . htmlspecialchars($allowed) . '"
514 data-target-folder="' . htmlspecialchars($folder->getCombinedIdentifier()) . '"
515 data-max-file-size="' . htmlspecialchars($maxFileSize) . '"
516 >';
517 $item .= $this->iconFactory->getIcon('actions-upload', Icon::SIZE_SMALL)->render() . ' ';
518 $item .= htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:file_upload.select-and-submit'));
519 $item .= '</a>';
520
521 $this->requireJsModules[] = ['TYPO3/CMS/Backend/DragUploader' => 'function(dragUploader){dragUploader.initialize()}'];
522 if (!empty($onlineMediaAllowed)) {
523 $buttonStyle = '';
524 if (isset($inlineConfiguration['inline']['inlineOnlineMediaAddButtonStyle'])) {
525 $buttonStyle = ' style="' . $inlineConfiguration['inline']['inlineOnlineMediaAddButtonStyle'] . '"';
526 }
527 $this->requireJsModules[] = 'TYPO3/CMS/Backend/OnlineMedia';
528 $buttonText = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:online_media.new_media.button'));
529 $placeholder = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:online_media.new_media.placeholder'));
530 $buttonSubmit = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:online_media.new_media.submit'));
531 $allowedMediaUrl = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.allowEmbedSources'));
532 $item .= '
533 <span class="btn btn-default t3js-online-media-add-btn ' . $this->inlineData['config'][$nameObject]['md5'] . '"
534 ' . $buttonStyle . '
535 data-file-irre-object="' . htmlspecialchars($objectPrefix) . '"
536 data-online-media-allowed="' . htmlspecialchars(implode(',', $onlineMediaAllowed)) . '"
537 data-online-media-allowed-help-text="' . $allowedMediaUrl . '"
538 data-target-folder="' . htmlspecialchars($folder->getCombinedIdentifier()) . '"
539 title="' . $buttonText . '"
540 data-btn-submit="' . $buttonSubmit . '"
541 data-placeholder="' . $placeholder . '"
542 >
543 ' . $this->iconFactory->getIcon('actions-online-media-add', Icon::SIZE_SMALL)->render() . '
544 ' . $buttonText . '</span>';
545 }
546 }
547 }
548
549 $item = '<div class="form-control-wrap">' . $item . '</div>';
550 $allowedList = '';
551 $allowedLabel = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.allowedFileExtensions'));
552 foreach ($allowedArray as $allowedItem) {
553 $allowedList .= '<span class="label label-success">' . strtoupper($allowedItem) . '</span> ';
554 }
555 if (!empty($allowedList)) {
556 $item .= '<div class="help-block">' . $allowedLabel . '<br>' . $allowedList . '</div>';
557 }
558 $item = '<div class="form-group t3js-formengine-validation-marker">' . $item . '</div>';
559 return $item;
560 }
561
562 /**
563 * Get a selector as used for the select type, to select from all available
564 * records and to create a relation to the embedding record (e.g. like MM).
565 *
566 * @param array $config TCA inline configuration of the parent(!) field
567 * @param array $uniqueIds The uids that have already been used and should be unique
568 * @return string A HTML <select> box with all possible records
569 */
570 protected function renderPossibleRecordsSelectorTypeSelect(array $config, array $uniqueIds)
571 {
572 $possibleRecords = $config['selectorOrUniquePossibleRecords'];
573 $nameObject = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid']);
574 // Create option tags:
575 $opt = [];
576 foreach ($possibleRecords as $p) {
577 if (!in_array($p[1], $uniqueIds)) {
578 $opt[] = '<option value="' . htmlspecialchars($p[1]) . '">' . htmlspecialchars($p[0]) . '</option>';
579 }
580 }
581 // Put together the selector box:
582 $size = (int)$config['size'];
583 $size = $config['autoSizeMax'] ? MathUtility::forceIntegerInRange(count($possibleRecords) + 1, MathUtility::forceIntegerInRange($size, 1), $config['autoSizeMax']) : $size;
584 $onChange = 'return inline.importNewRecord(' . GeneralUtility::quoteJSvalue($nameObject . '-' . $config['foreign_table']) . ')';
585 $item = '
586 <select id="' . $nameObject . '-' . $config['foreign_table'] . '_selector" class="form-control"' . ($size ? ' size="' . $size . '"' : '')
587 . ' onchange="' . htmlspecialchars($onChange) . '"' . ($config['foreign_unique'] ? ' isunique="isunique"' : '') . '>
588 ' . implode('', $opt) . '
589 </select>';
590
591 if ($size <= 1) {
592 // Add a "Create new relation" link for adding new relations
593 // This is necessary, if the size of the selector is "1" or if
594 // there is only one record item in the select-box, that is selected by default
595 // The selector-box creates a new relation on using an onChange event (see some line above)
596 if (!empty($config['appearance']['createNewRelationLinkTitle'])) {
597 $createNewRelationText = htmlspecialchars($this->getLanguageService()->sL($config['appearance']['createNewRelationLinkTitle']));
598 } else {
599 $createNewRelationText = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.createNewRelation'));
600 }
601 $item .= '
602 <span class="input-group-btn">
603 <a href="#" class="btn btn-default" onclick="' . htmlspecialchars($onChange) . '" title="' . $createNewRelationText . '">
604 ' . $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render() . $createNewRelationText . '
605 </a>
606 </span>';
607 } else {
608 $item .= '
609 <span class="input-group-btn btn"></span>';
610 }
611
612 // Wrap the selector and add a spacer to the bottom
613 $item = '<div class="input-group form-group t3js-formengine-validation-marker ' . $this->inlineData['config'][$nameObject]['md5'] . '">' . $item . '</div>';
614 return $item;
615 }
616
617 /**
618 * Extracts FlexForm parts of a form element name like
619 * data[table][uid][field][sDEF][lDEF][FlexForm][vDEF]
620 * Helper method used in inline
621 *
622 * @param string $formElementName The form element name
623 * @return array|null
624 */
625 protected function extractFlexFormParts($formElementName)
626 {
627 $flexFormParts = null;
628 $matches = [];
629 if (preg_match('#^data(?:\[[^]]+\]){3}(\[data\](?:\[[^]]+\]){4,})$#', $formElementName, $matches)) {
630 $flexFormParts = GeneralUtility::trimExplode(
631 '][',
632 trim($matches[1], '[]')
633 );
634 }
635 return $flexFormParts;
636 }
637
638 /**
639 * @return BackendUserAuthentication
640 */
641 protected function getBackendUserAuthentication()
642 {
643 return $GLOBALS['BE_USER'];
644 }
645
646 /**
647 * @return LanguageService
648 */
649 protected function getLanguageService()
650 {
651 return $GLOBALS['LANG'];
652 }
653 }