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