4d9ca36f6e40682da1f5e01c7aad5b2cf3bfa410
[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\FormDataCompiler;
18 use TYPO3\CMS\Backend\Form\FormDataGroup\OnTheFly;
19 use TYPO3\CMS\Backend\Form\FormDataProvider\TcaSelectItems;
20 use TYPO3\CMS\Backend\Form\NodeFactory;
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
22 use TYPO3\CMS\Core\Imaging\Icon;
23 use TYPO3\CMS\Core\Imaging\IconFactory;
24 use TYPO3\CMS\Core\Resource\Folder;
25 use TYPO3\CMS\Core\Utility\MathUtility;
26 use TYPO3\CMS\Core\Utility\GeneralUtility;
27 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
28 use TYPO3\CMS\Lang\LanguageService;
29 use TYPO3\CMS\Core\Utility\ArrayUtility;
30 use TYPO3\CMS\Backend\Form\Utility\FormEngineUtility;
31 use TYPO3\CMS\Backend\Utility\IconUtility;
32 use TYPO3\CMS\Backend\Form\InlineStackProcessor;
33 use TYPO3\CMS\Backend\Form\InlineRelatedRecordResolver;
34 use TYPO3\CMS\Backend\Form\Exception\AccessDeniedException;
35
36 /**
37 * Inline element entry container.
38 *
39 * This container is the entry step to rendering an inline element. It is created by SingleFieldContainer.
40 *
41 * The code creates the main structure for the single inline elements, initializes
42 * the inlineData array, that is manipulated and also returned back in its manipulated state.
43 * The "control" stuff of inline elements is rendered here, for example the "create new" button.
44 *
45 * For each existing inline relation an InlineRecordContainer is called for further processing.
46 */
47 class InlineControlContainer extends AbstractContainer {
48
49 /**
50 * Inline data array used in JS, returned as JSON object to frontend
51 *
52 * @var array
53 */
54 protected $inlineData = array();
55
56 /**
57 * @var InlineStackProcessor
58 */
59 protected $inlineStackProcessor;
60
61 /**
62 * @var IconFactory
63 */
64 protected $iconFactory;
65
66 /**
67 * Container objects give $nodeFactory down to other containers.
68 *
69 * @param NodeFactory $nodeFactory
70 * @param array $data
71 */
72 public function __construct(NodeFactory $nodeFactory, array $data) {
73 parent::__construct($nodeFactory, $data);
74 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
75 }
76
77 /**
78 * Entry method
79 *
80 * @return array As defined in initializeResultArray() of AbstractNode
81 */
82 public function render() {
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 $html = '';
99
100 // An inline field must have a foreign_table, if not, stop all further inline actions for this field
101 if (
102 !$parameterArray['fieldConf']['config']['foreign_table']
103 || !is_array($GLOBALS['TCA'][$parameterArray['fieldConf']['config']['foreign_table']])
104 ) {
105 return $resultArray;
106 }
107
108 $config = FormEngineUtility::mergeInlineConfiguration($parameterArray['fieldConf']['config']);
109 $foreign_table = $config['foreign_table'];
110
111 $language = 0;
112 if (BackendUtility::isTableLocalizable($table)) {
113 $language = (int)$row[$GLOBALS['TCA'][$table]['ctrl']['languageField']];
114 }
115 $minItems = MathUtility::forceIntegerInRange($config['minitems'], 0);
116 $maxItems = MathUtility::forceIntegerInRange($config['maxitems'], 0);
117 if (!$maxItems) {
118 $maxItems = 100000;
119 }
120
121 // Add the current inline job to the structure stack
122 $newStructureItem = array(
123 'table' => $table,
124 'uid' => $row['uid'],
125 'field' => $field,
126 'config' => $config,
127 'localizationMode' => BackendUtility::getInlineLocalizationMode($table, $config),
128 );
129 // Extract FlexForm parts (if any) from element name, e.g. array('vDEF', 'lDEF', 'FlexField', 'vDEF')
130 if (!empty($parameterArray['itemFormElName'])) {
131 $flexFormParts = FormEngineUtility::extractFlexFormParts($parameterArray['itemFormElName']);
132 if ($flexFormParts !== NULL) {
133 $newStructureItem['flexform'] = $flexFormParts;
134 }
135 }
136 $inlineStackProcessor->pushStableStructureItem($newStructureItem);
137
138 // e.g. data[<table>][<uid>][<field>]
139 $nameForm = $inlineStackProcessor->getCurrentStructureFormPrefix();
140 // e.g. data-<pid>-<table1>-<uid1>-<field1>-<table2>-<uid2>-<field2>
141 $nameObject = $inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid']);
142
143 // Get the records related to this inline record
144 /** @var InlineRelatedRecordResolver $inlineRelatedRecordResolver */
145 $inlineRelatedRecordResolver = GeneralUtility::makeInstance(InlineRelatedRecordResolver::class);
146 $relatedRecords = $inlineRelatedRecordResolver->getRelatedRecords($table, $field, $row, $parameterArray, $config, $this->data['inlineFirstPid']);
147
148 // Set the first and last record to the config array
149 $relatedRecordsUids = array_keys($relatedRecords['records']);
150 $config['inline']['first'] = reset($relatedRecordsUids);
151 $config['inline']['last'] = end($relatedRecordsUids);
152
153 $top = $inlineStackProcessor->getStructureLevel(0);
154
155 $this->inlineData['config'][$nameObject] = array(
156 'table' => $foreign_table,
157 'md5' => md5($nameObject)
158 );
159 $this->inlineData['config'][$nameObject . '-' . $foreign_table] = array(
160 'min' => $minItems,
161 'max' => $maxItems,
162 'sortable' => $config['appearance']['useSortable'],
163 'top' => array(
164 'table' => $top['table'],
165 'uid' => $top['uid']
166 ),
167 'context' => array(
168 'config' => $config,
169 'hmac' => GeneralUtility::hmac(serialize($config)),
170 ),
171 );
172 $this->inlineData['nested'][$nameObject] = $this->data['tabAndInlineStack'];
173
174 // If relations are required to be unique, get the uids that have already been used on the foreign side of the relation
175 if ($config['foreign_unique']) {
176 // If uniqueness *and* selector are set, they should point to the same field - so, get the configuration of one:
177 $selConfig = FormEngineUtility::getInlinePossibleRecordsSelectorConfig($config, $config['foreign_unique']);
178 // Get the used unique ids:
179 $uniqueIds = $this->getUniqueIds($relatedRecords['records'], $config, $selConfig['type'] == 'groupdb');
180 $possibleRecords = $this->getPossibleRecords($table, $field, $row, $config, 'foreign_unique');
181 $uniqueMax = $config['appearance']['useCombination'] || $possibleRecords === FALSE ? -1 : count($possibleRecords);
182 $this->inlineData['unique'][$nameObject . '-' . $foreign_table] = array(
183 'max' => $uniqueMax,
184 'used' => $uniqueIds,
185 'type' => $selConfig['type'],
186 'table' => $config['foreign_table'],
187 'elTable' => $selConfig['table'],
188 // element/record table (one step down in hierarchy)
189 'field' => $config['foreign_unique'],
190 'selector' => $selConfig['selector'],
191 'possible' => $this->getPossibleRecordsFlat($possibleRecords)
192 );
193 }
194
195 $resultArray['inlineData'] = $this->inlineData;
196
197 // Render the localization links
198 $localizationLinks = '';
199 if ($language > 0 && $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] > 0 && MathUtility::canBeInterpretedAsInteger($row['uid'])) {
200 // Add the "Localize all records" link before all child records:
201 if (isset($config['appearance']['showAllLocalizationLink']) && $config['appearance']['showAllLocalizationLink']) {
202 $localizationLinks .= ' ' . $this->getLevelInteractionLink('localize', $nameObject . '-' . $foreign_table, $config);
203 }
204 // Add the "Synchronize with default language" link before all child records:
205 if (isset($config['appearance']['showSynchronizationLink']) && $config['appearance']['showSynchronizationLink']) {
206 $localizationLinks .= ' ' . $this->getLevelInteractionLink('synchronize', $nameObject . '-' . $foreign_table, $config);
207 }
208 }
209
210 // Define how to show the "Create new record" link - if there are more than maxitems, hide it
211 if ($relatedRecords['count'] >= $maxItems || $uniqueMax > 0 && $relatedRecords['count'] >= $uniqueMax) {
212 $config['inline']['inlineNewButtonStyle'] = 'display: none;';
213 $config['inline']['inlineNewRelationButtonStyle'] = 'display: none;';
214 }
215
216 // Render the level links (create new record):
217 $levelLinks = $this->getLevelInteractionLink('newRecord', $nameObject . '-' . $foreign_table, $config);
218
219 // Wrap all inline fields of a record with a <div> (like a container)
220 $html .= '<div class="form-group" id="' . $nameObject . '">';
221 // Add the level links before all child records:
222 if ($config['appearance']['levelLinksPosition'] === 'both' || $config['appearance']['levelLinksPosition'] === 'top') {
223 $html .= '<div class="form-group t3js-formengine-validation-marker">' . $levelLinks . $localizationLinks . '</div>';
224 }
225 // If it's required to select from possible child records (reusable children), add a selector box
226 if ($config['foreign_selector'] && $config['appearance']['showPossibleRecordsSelector'] !== FALSE) {
227 // If not already set by the foreign_unique, set the possibleRecords here and the uniqueIds to an empty array
228 if (!$config['foreign_unique']) {
229 $possibleRecords = $this->getPossibleRecords($table, $field, $row, $config);
230 $uniqueIds = array();
231 }
232 $selectorBox = $this->renderPossibleRecordsSelector($possibleRecords, $config, $uniqueIds);
233 $html .= $selectorBox . $localizationLinks;
234 }
235 $title = $languageService->sL($parameterArray['fieldConf']['label']);
236 $html .= '<div class="panel-group panel-hover" data-title="' . htmlspecialchars($title) . '" id="' . $nameObject . '_records">';
237
238 $relationList = array();
239 if (!empty($relatedRecords['records'])) {
240 foreach ($relatedRecords['records'] as $rec) {
241 $options = $this->data;
242 $options['inlineRelatedRecordToRender'] = $rec;
243 $options['inlineRelatedRecordConfig'] = $config;
244 $options['inlineData'] = $this->inlineData;
245 $options['inlineStructure'] = $inlineStackProcessor->getStructure();
246 $options['renderType'] = 'inlineRecordContainer';
247 try {
248 // This container may raise an access denied exception, to not kill further processing,
249 // just a simple "empty" return is created here to ignore this field.
250 $childArray = $this->nodeFactory->create($options)->render();
251 } catch (AccessDeniedException $e) {
252 $childArray = $this->initializeResultArray();
253 }
254 $html .= $childArray['html'];
255 $childArray['html'] = '';
256 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childArray);
257 if (!isset($rec['__virtual']) || !$rec['__virtual']) {
258 $relationList[] = $rec['uid'];
259 }
260 }
261 }
262 $html .= '</div>';
263 // Add the level links after all child records:
264 if ($config['appearance']['levelLinksPosition'] === 'both' || $config['appearance']['levelLinksPosition'] === 'bottom') {
265 $html .= $levelLinks . $localizationLinks;
266 }
267 if (is_array($config['customControls'])) {
268 $html .= '<div id="' . $nameObject . '_customControls">';
269 foreach ($config['customControls'] as $customControlConfig) {
270 $parameters = array(
271 'table' => $table,
272 'field' => $field,
273 'row' => $row,
274 'nameObject' => $nameObject,
275 'nameForm' => $nameForm,
276 'config' => $config
277 );
278 $html .= GeneralUtility::callUserFunction($customControlConfig, $parameters, $this);
279 }
280 $html .= '</div>';
281 }
282 // Add Drag&Drop functions for sorting to FormEngine::$additionalJS_post
283 if (count($relationList) > 1 && $config['appearance']['useSortable']) {
284 $resultArray['additionalJavaScriptPost'][] = 'inline.createDragAndDropSorting("' . $nameObject . '_records' . '");';
285 }
286 // Publish the uids of the child records in the given order to the browser
287 $html .= '<input type="hidden" name="' . $nameForm . '" value="' . implode(',', $relationList) . '" ' . $this->getValidationDataAsDataAttribute(array('type' => 'inline', 'minitems' => $minItems, 'maxitems' => $maxItems)) . ' class="inlineRecord" />';
288 // Close the wrap for all inline fields (container)
289 $html .= '</div>';
290
291 $resultArray['html'] = $html;
292 return $resultArray;
293 }
294
295 /**
296 * Gets the uids of a select/selector that should be unique and have already been used.
297 *
298 * @param array $records All inline records on this level
299 * @param array $conf The TCA field configuration of the inline field to be rendered
300 * @param bool $splitValue For usage with group/db, values come like "tx_table_123|Title%20abc", but we need "tx_table" and "123
301 * @return array The uids, that have been used already and should be used unique
302 */
303 protected function getUniqueIds($records, $conf = array(), $splitValue = FALSE) {
304 $uniqueIds = array();
305 if (isset($conf['foreign_unique']) && $conf['foreign_unique'] && !empty($records)) {
306 foreach ($records as $rec) {
307 // Skip virtual records (e.g. shown in localization mode):
308 if (!isset($rec['__virtual']) || !$rec['__virtual']) {
309 $value = $rec[$conf['foreign_unique']];
310 // Split the value and extract the table and uid:
311 if ($splitValue) {
312 $valueParts = GeneralUtility::trimExplode('|', $value);
313 $itemParts = explode('_', $valueParts[0]);
314 $value = array(
315 'uid' => array_pop($itemParts),
316 'table' => implode('_', $itemParts)
317 );
318 }
319 $uniqueIds[$rec['uid']] = $value;
320 }
321 }
322 }
323 return $uniqueIds;
324 }
325
326 /**
327 * Get possible records.
328 * Copied from FormEngine and modified.
329 *
330 * @param string $table The table name of the record
331 * @param string $field The field name which this element is supposed to edit
332 * @param array $row The record data array where the value(s) for the field can be found
333 * @param array $conf An array with additional configuration options.
334 * @param string $checkForConfField For which field in the foreign_table the possible records should be fetched
335 * @return mixed Array of possible record items; FALSE if type is "group/db", then everything could be "possible
336 */
337 protected function getPossibleRecords($table, $field, $row, $conf, $checkForConfField = 'foreign_selector') {
338 // Field configuration from TCA:
339 $foreign_check = $conf[$checkForConfField];
340 $foreignConfig = FormEngineUtility::getInlinePossibleRecordsSelectorConfig($conf, $foreign_check);
341 $PA = $foreignConfig['PA'];
342 if ($foreignConfig['type'] == 'select') {
343 $pageTsConfig['TCEFORM.']['dummyTable.']['dummyField.'] = $PA['fieldTSConfig'];
344 $selectDataInput = [
345 'tableName' => 'dummyTable',
346 'command' => 'edit',
347 'pageTsConfigMerged' => $pageTsConfig,
348 'vanillaTableTca' => [
349 'ctrl' => [],
350 'columns' => [
351 'dummyField' => $PA['fieldConf'],
352 ],
353 ],
354 'processedTca' => [
355 'ctrl' => [],
356 'columns' => [
357 'dummyField' => $PA['fieldConf'],
358 ],
359 ],
360 ];
361
362 /** @var OnTheFly $formDataGroup */
363 $formDataGroup = GeneralUtility::makeInstance(OnTheFly::class);
364 $formDataGroup->setProviderList([ TcaSelectItems::class ]);
365 /** @var FormDataCompiler $formDataCompiler */
366 $formDataCompiler = GeneralUtility::makeInstance(FormDataCompiler::class, $formDataGroup);
367 $compilerResult = $formDataCompiler->compile($selectDataInput);
368 $selItems = $compilerResult['processedTca']['columns']['dummyField']['config']['items'];
369 } else {
370 $selItems = FALSE;
371 }
372 return $selItems;
373 }
374
375 /**
376 * Makes a flat array from the $possibleRecords array.
377 * The key of the flat array is the value of the record,
378 * the value of the flat array is the label of the record.
379 *
380 * @param array $possibleRecords The possibleRecords array (for select fields)
381 * @return mixed A flat array with key=uid, value=label; if $possibleRecords isn't an array, FALSE is returned.
382 */
383 protected function getPossibleRecordsFlat($possibleRecords) {
384 $flat = FALSE;
385 if (is_array($possibleRecords)) {
386 $flat = array();
387 foreach ($possibleRecords as $record) {
388 $flat[$record[1]] = $record[0];
389 }
390 }
391 return $flat;
392 }
393
394 /**
395 * Creates the HTML code of a general link to be used on a level of inline children.
396 * The possible keys for the parameter $type are 'newRecord', 'localize' and 'synchronize'.
397 *
398 * @param string $type The link type, values are 'newRecord', 'localize' and 'synchronize'.
399 * @param string $objectPrefix The "path" to the child record to create (e.g. 'data-parentPageId-partenTable-parentUid-parentField-childTable]')
400 * @param array $conf TCA configuration of the parent(!) field
401 * @return string The HTML code of the new link, wrapped in a div
402 */
403 protected function getLevelInteractionLink($type, $objectPrefix, $conf = array()) {
404 $languageService = $this->getLanguageService();
405 $nameObject = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid']);
406 $attributes = array();
407 switch ($type) {
408 case 'newRecord':
409 $title = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:cm.createnew', TRUE);
410 $icon = 'actions-document-new';
411 $className = 'typo3-newRecordLink';
412 $attributes['class'] = 'btn btn-default inlineNewButton ' . $this->inlineData['config'][$nameObject]['md5'];
413 $attributes['onclick'] = 'return inline.createNewRecord(' . GeneralUtility::quoteJSvalue($objectPrefix) . ')';
414 if (!empty($conf['inline']['inlineNewButtonStyle'])) {
415 $attributes['style'] = $conf['inline']['inlineNewButtonStyle'];
416 }
417 if (!empty($conf['appearance']['newRecordLinkAddTitle'])) {
418 $title = sprintf(
419 $languageService->sL('LLL:EXT:lang/locallang_core.xlf:cm.createnew.link', TRUE),
420 $languageService->sL($GLOBALS['TCA'][$conf['foreign_table']]['ctrl']['title'], TRUE)
421 );
422 } elseif (isset($conf['appearance']['newRecordLinkTitle']) && $conf['appearance']['newRecordLinkTitle'] !== '') {
423 $title = $languageService->sL($conf['appearance']['newRecordLinkTitle'], TRUE);
424 }
425 break;
426 case 'localize':
427 $title = $languageService->sL('LLL:EXT:lang/locallang_misc.xlf:localizeAllRecords', TRUE);
428 $icon = 'actions-document-localize';
429 $className = 'typo3-localizationLink';
430 $attributes['class'] = 'btn btn-default';
431 $attributes['onclick'] = 'return inline.synchronizeLocalizeRecords(' . GeneralUtility::quoteJSvalue($objectPrefix) . ', \'localize\')';
432 break;
433 case 'synchronize':
434 $title = $languageService->sL('LLL:EXT:lang/locallang_misc.xlf:synchronizeWithOriginalLanguage', TRUE);
435 $icon = 'actions-document-synchronize';
436 $className = 'typo3-synchronizationLink';
437 $attributes['class'] = 'btn btn-default inlineNewButton ' . $this->inlineData['config'][$nameObject]['md5'];
438 $attributes['onclick'] = 'return inline.synchronizeLocalizeRecords(' . GeneralUtility::quoteJSvalue($objectPrefix) . ', \'synchronize\')';
439 break;
440 default:
441 $title = '';
442 $icon = '';
443 $className = '';
444 }
445 // Create the link:
446 $icon = $icon ? $this->iconFactory->getIcon($icon, Icon::SIZE_SMALL) : '';
447 $link = $this->wrapWithAnchor($icon . $title, '#', $attributes);
448 return '<div' . ($className ? ' class="' . $className . '"' : '') . 'title="' . $title . '">' . $link . '</div>';
449 }
450
451 /**
452 * Wraps a text with an anchor and returns the HTML representation.
453 *
454 * @param string $text The text to be wrapped by an anchor
455 * @param string $link The link to be used in the anchor
456 * @param array $attributes Array of attributes to be used in the anchor
457 * @return string The wrapped text as HTML representation
458 */
459 protected function wrapWithAnchor($text, $link, $attributes = array()) {
460 $link = trim($link);
461 $result = '<a href="' . ($link ?: '#') . '"';
462 foreach ($attributes as $key => $value) {
463 $result .= ' ' . $key . '="' . htmlspecialchars(trim($value)) . '"';
464 }
465 $result .= '>' . $text . '</a>';
466 return $result;
467 }
468
469 /**
470 * Get a selector as used for the select type, to select from all available
471 * records and to create a relation to the embedding record (e.g. like MM).
472 *
473 * @param array $selItems Array of all possible records
474 * @param array $conf TCA configuration of the parent(!) field
475 * @param array $uniqueIds The uids that have already been used and should be unique
476 * @return string A HTML <select> box with all possible records
477 */
478 protected function renderPossibleRecordsSelector($selItems, $conf, $uniqueIds = array()) {
479 $foreign_selector = $conf['foreign_selector'];
480 $selConfig = FormEngineUtility::getInlinePossibleRecordsSelectorConfig($conf, $foreign_selector);
481 $item = '';
482 if ($selConfig['type'] === 'select') {
483 $item = $this->renderPossibleRecordsSelectorTypeSelect($selItems, $conf, $selConfig['PA'], $uniqueIds);
484 } elseif ($selConfig['type'] === 'groupdb') {
485 $item = $this->renderPossibleRecordsSelectorTypeGroupDB($conf, $selConfig['PA']);
486 }
487 return $item;
488 }
489
490 /**
491 * Generate a link that opens an element browser in a new window.
492 * For group/db there is no way to use a "selector" like a <select>|</select>-box.
493 *
494 * @param array $conf TCA configuration of the parent(!) field
495 * @param array $PA An array with additional configuration options
496 * @return string A HTML link that opens an element browser in a new window
497 */
498 protected function renderPossibleRecordsSelectorTypeGroupDB($conf, &$PA) {
499 $backendUser = $this->getBackendUserAuthentication();
500
501 $config = $PA['fieldConf']['config'];
502 ArrayUtility::mergeRecursiveWithOverrule($config, $conf);
503 $foreign_table = $config['foreign_table'];
504 $allowed = $config['allowed'];
505 $objectPrefix = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid']) . '-' . $foreign_table;
506 $nameObject = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid']);
507 $mode = 'db';
508 $showUpload = FALSE;
509 if (!empty($config['appearance']['createNewRelationLinkTitle'])) {
510 $createNewRelationText = $this->getLanguageService()->sL($config['appearance']['createNewRelationLinkTitle'], TRUE);
511 } else {
512 $createNewRelationText = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.createNewRelation', TRUE);
513 }
514 if (is_array($config['appearance'])) {
515 if (isset($config['appearance']['elementBrowserType'])) {
516 $mode = $config['appearance']['elementBrowserType'];
517 }
518 if ($mode === 'file') {
519 $showUpload = TRUE;
520 }
521 if (isset($config['appearance']['fileUploadAllowed'])) {
522 $showUpload = (bool)$config['appearance']['fileUploadAllowed'];
523 }
524 if (isset($config['appearance']['elementBrowserAllowed'])) {
525 $allowed = $config['appearance']['elementBrowserAllowed'];
526 }
527 }
528 $browserParams = '|||' . $allowed . '|' . $objectPrefix . '|inline.checkUniqueElement||inline.importElement';
529 $onClick = 'setFormValueOpenBrowser(' . GeneralUtility::quoteJSvalue($mode) . ', ' . GeneralUtility::quoteJSvalue($browserParams) . '); return false;';
530
531 $buttonStyle = '';
532 if (isset($config['inline']['inlineNewRelationButtonStyle'])) {
533 $buttonStyle = ' style="' . $config['inline']['inlineNewRelationButtonStyle'] . '"';
534 }
535
536 $item = '
537 <a href="#" class="btn btn-default inlineNewRelationButton ' . $this->inlineData['config'][$nameObject]['md5'] . '"
538 ' . $buttonStyle . ' onclick="' . htmlspecialchars($onClick) . '" title="' . $createNewRelationText . '">
539 ' . $this->iconFactory->getIcon('actions-insert-record', Icon::SIZE_SMALL) . '
540 ' . $createNewRelationText . '
541 </a>';
542
543 $isDirectFileUploadEnabled = (bool)$this->getBackendUserAuthentication()->uc['edit_docModuleUpload'];
544 if ($showUpload && $isDirectFileUploadEnabled) {
545 $folder = $backendUser->getDefaultUploadFolder();
546 if (
547 $folder instanceof Folder
548 && $folder->checkActionPermission('add')
549 ) {
550 $maxFileSize = GeneralUtility::getMaxUploadFileSize() * 1024;
551 $item .= ' <a href="#" class="btn btn-default t3js-drag-uploader inlineNewFileUploadButton ' . $this->inlineData['config'][$nameObject]['md5'] . '"
552 ' . $buttonStyle . '
553 data-dropzone-target="#' . htmlspecialchars($this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid'])) . '"
554 data-insert-dropzone-before="1"
555 data-file-irre-object="' . htmlspecialchars($objectPrefix) . '"
556 data-file-allowed="' . htmlspecialchars($allowed) . '"
557 data-target-folder="' . htmlspecialchars($folder->getCombinedIdentifier()) . '"
558 data-max-file-size="' . htmlspecialchars($maxFileSize) . '"
559 ><span class="t3-icon t3-icon-actions t3-icon-actions-edit t3-icon-edit-upload">&nbsp;</span>';
560 $item .= $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.select-and-submit', TRUE);
561 $item .= '</a>';
562 }
563 }
564
565 $item = '<div class="form-control-wrap">' . $item . '</div>';
566 $allowedList = '';
567 $allowedArray = GeneralUtility::trimExplode(',', $allowed, TRUE);
568 $allowedLabel = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.allowedFileExtensions', TRUE);
569 foreach ($allowedArray as $allowedItem) {
570 $allowedList .= '<span class="label label-success">' . strtoupper($allowedItem) . '</span> ';
571 }
572 if (!empty($allowedList)) {
573 $item .= '<div class="help-block">' . $allowedLabel . '<br>' . $allowedList . '</div>';
574 }
575 $item = '<div class="form-group t3js-formengine-validation-marker">' . $item . '</div>';
576 return $item;
577 }
578
579 /**
580 * Get a selector as used for the select type, to select from all available
581 * records and to create a relation to the embedding record (e.g. like MM).
582 *
583 * @param array $selItems Array of all possible records
584 * @param array $conf TCA configuration of the parent(!) field
585 * @param array $PA An array with additional configuration options
586 * @param array $uniqueIds The uids that have already been used and should be unique
587 * @return string A HTML <select> box with all possible records
588 */
589 protected function renderPossibleRecordsSelectorTypeSelect($selItems, $conf, &$PA, $uniqueIds = array()) {
590 $foreign_table = $conf['foreign_table'];
591 $foreign_selector = $conf['foreign_selector'];
592 $PA = array();
593 $PA['fieldConf'] = $GLOBALS['TCA'][$foreign_table]['columns'][$foreign_selector];
594 $PA['fieldTSConfig'] = FormEngineUtility::getTSconfigForTableRow($foreign_table, array(), $foreign_selector);
595 $config = $PA['fieldConf']['config'];
596 $item = '';
597 // @todo $disabled is not present - should be read from config?
598 $disabled = FALSE;
599 if (!$disabled) {
600 $nameObject = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid']);;
601 // Create option tags:
602 $opt = array();
603 foreach ($selItems as $p) {
604 if (!in_array($p[1], $uniqueIds)) {
605 $opt[] = '<option value="' . htmlspecialchars($p[1]) . '">' . htmlspecialchars($p[0]) . '</option>';
606 }
607 }
608 // Put together the selector box:
609 $itemListStyle = isset($config['itemListStyle']) ? ' style="' . htmlspecialchars($config['itemListStyle']) . '"' : '';
610 $size = (int)$conf['size'];
611 $size = $conf['autoSizeMax'] ? MathUtility::forceIntegerInRange(count($selItems) + 1, MathUtility::forceIntegerInRange($size, 1), $conf['autoSizeMax']) : $size;
612 $onChange = 'return inline.importNewRecord(' . GeneralUtility::quoteJSvalue($nameObject . '-' . $conf['foreign_table']) . ')';
613 $item = '
614 <select id="' . $nameObject . '-' . $conf['foreign_table'] . '_selector" class="form-control"' . ($size ? ' size="' . $size . '"' : '') . ' onchange="' . htmlspecialchars($onChange) . '"' . $PA['onFocus'] . $itemListStyle . ($conf['foreign_unique'] ? ' isunique="isunique"' : '') . '>
615 ' . implode('', $opt) . '
616 </select>';
617
618 if ($size <= 1) {
619 // Add a "Create new relation" link for adding new relations
620 // This is necessary, if the size of the selector is "1" or if
621 // there is only one record item in the select-box, that is selected by default
622 // The selector-box creates a new relation on using an onChange event (see some line above)
623 if (!empty($conf['appearance']['createNewRelationLinkTitle'])) {
624 $createNewRelationText = $this->getLanguageService()->sL($conf['appearance']['createNewRelationLinkTitle'], TRUE);
625 } else {
626 $createNewRelationText = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.createNewRelation', TRUE);
627 }
628 $item .= '
629 <span class="input-group-btn">
630 <a href="#" class="btn btn-default" onclick="' . htmlspecialchars($onChange) . '" . title="' . $createNewRelationText .'">
631 ' . $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL) . $createNewRelationText . '
632 </a>
633 </span>';
634 } else {
635 $item .= '
636 <span class="input-group-btn btn"></span>';
637 }
638
639 // Wrap the selector and add a spacer to the bottom
640
641 $item = '<div class="input-group form-group t3js-formengine-validation-marker ' . $this->inlineData['config'][$nameObject]['md5'] . '">' . $item . '</div>';
642 }
643 return $item;
644 }
645
646 /**
647 * @return BackendUserAuthentication
648 */
649 protected function getBackendUserAuthentication() {
650 return $GLOBALS['BE_USER'];
651 }
652
653 /**
654 * @return LanguageService
655 */
656 protected function getLanguageService() {
657 return $GLOBALS['LANG'];
658 }
659
660 }