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