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