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