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