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