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