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