[!!!][TASK] Improve flex and TCA handling in FormEngine
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / Container / InlineRecordContainer.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\Element\InlineElementHookInterface;
18 use TYPO3\CMS\Backend\Form\Exception\AccessDeniedContentEditException;
19 use TYPO3\CMS\Backend\Form\InlineStackProcessor;
20 use TYPO3\CMS\Backend\Form\NodeFactory;
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
22 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
23 use TYPO3\CMS\Core\Database\ConnectionPool;
24 use TYPO3\CMS\Core\Imaging\Icon;
25 use TYPO3\CMS\Core\Imaging\IconFactory;
26 use TYPO3\CMS\Core\Messaging\FlashMessage;
27 use TYPO3\CMS\Core\Resource\ProcessedFile;
28 use TYPO3\CMS\Core\Resource\ResourceFactory;
29 use TYPO3\CMS\Core\Type\Bitmask\Permission;
30 use TYPO3\CMS\Core\Utility\GeneralUtility;
31 use TYPO3\CMS\Core\Utility\MathUtility;
32 use TYPO3\CMS\Lang\LanguageService;
33
34 /**
35 * Render a single inline record relation.
36 *
37 * This container is called by InlineControlContainer to render single existing records.
38 * Furthermore it is called by FormEngine for an incoming ajax request to expand an existing record
39 * or to create a new one.
40 *
41 * This container creates the outer HTML of single inline records - eg. drag and drop and delete buttons.
42 * For rendering of the record itself processing is handed over to FullRecordContainer.
43 */
44 class InlineRecordContainer extends AbstractContainer
45 {
46 /**
47 * Inline data array used for JSON output
48 *
49 * @var array
50 */
51 protected $inlineData = [];
52
53 /**
54 * @var InlineStackProcessor
55 */
56 protected $inlineStackProcessor;
57
58 /**
59 * Array containing instances of hook classes called once for IRRE objects
60 *
61 * @var array
62 */
63 protected $hookObjects = [];
64
65 /**
66 * @var IconFactory
67 */
68 protected $iconFactory;
69
70 /**
71 * Default constructor
72 *
73 * @param NodeFactory $nodeFactory
74 * @param array $data
75 */
76 public function __construct(NodeFactory $nodeFactory, array $data)
77 {
78 parent::__construct($nodeFactory, $data);
79 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
80 $this->inlineStackProcessor = GeneralUtility::makeInstance(InlineStackProcessor::class);
81 $this->initHookObjects();
82 }
83
84 /**
85 * Entry method
86 *
87 * @return array As defined in initializeResultArray() of AbstractNode
88 * @throws AccessDeniedContentEditException
89 */
90 public function render()
91 {
92 $data = $this->data;
93 $this->inlineData = $data['inlineData'];
94
95 $inlineStackProcessor = $this->inlineStackProcessor;
96 $inlineStackProcessor->initializeByGivenStructure($data['inlineStructure']);
97
98 $record = $data['databaseRow'];
99 $inlineConfig = $data['inlineParentConfig'];
100 $foreignTable = $inlineConfig['foreign_table'];
101
102 $resultArray = $this->initializeResultArray();
103
104 // Send a mapping information to the browser via JSON:
105 // e.g. data[<curTable>][<curId>][<curField>] => data-<pid>-<parentTable>-<parentId>-<parentField>-<curTable>-<curId>-<curField>
106 $formPrefix = $inlineStackProcessor->getCurrentStructureFormPrefix();
107 $domObjectId = $inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($data['inlineFirstPid']);
108 $this->inlineData['map'][$formPrefix] = $domObjectId;
109
110 $resultArray['inlineData'] = $this->inlineData;
111
112 // If there is a selector field, normalize it:
113 if (!empty($inlineConfig['foreign_selector'])) {
114 $foreign_selector = $inlineConfig['foreign_selector'];
115 $valueToNormalize = $record[$foreign_selector];
116 if (is_array($record[$foreign_selector])) {
117 // @todo: this can be kicked again if always prepared rows are handled here
118 $valueToNormalize = implode(',', $record[$foreign_selector]);
119 }
120 $record[$foreign_selector] = $this->normalizeUid($valueToNormalize);
121 }
122
123 // Get the current naming scheme for DOM name/id attributes:
124 $appendFormFieldNames = '[' . $foreignTable . '][' . $record['uid'] . ']';
125 $objectId = $domObjectId . '-' . $foreignTable . '-' . $record['uid'];
126 $class = '';
127 $html = '';
128 $combinationHtml = '';
129 $isNewRecord = $data['command'] === 'new';
130 $hiddenField = '';
131 if (isset($data['processedTca']['ctrl']['enablecolumns']['disabled'])) {
132 $hiddenField = $data['processedTca']['ctrl']['enablecolumns']['disabled'];
133 }
134 if (!$data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
135 if ($isNewRecord || $data['isInlineChildExpanded']) {
136 // Render full content ONLY IF this is an AJAX request, a new record, or the record is not collapsed
137 $combinationHtml = '';
138 if (isset($data['combinationChild'])) {
139 $combinationChild = $this->renderCombinationChild($data, $appendFormFieldNames);
140 $combinationHtml = $combinationChild['html'];
141 $combinationChild['html'] = '';
142 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $combinationChild);
143 }
144 $childArray = $this->renderChild($data);
145 $html = $childArray['html'];
146 $childArray['html'] = '';
147 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childArray);
148 } else {
149 // This string is the marker for the JS-function to check if the full content has already been loaded
150 $html = '<!--notloaded-->';
151 }
152 if ($isNewRecord) {
153 // Add pid of record as hidden field
154 $html .= '<input type="hidden" name="data' . htmlspecialchars($appendFormFieldNames)
155 . '[pid]" value="' . htmlspecialchars($record['pid']) . '"/>';
156 // Tell DataHandler this record is expanded
157 $ucFieldName = 'uc[inlineView]'
158 . '[' . $data['inlineTopMostParentTableName'] . ']'
159 . '[' . $data['inlineTopMostParentUid'] . ']'
160 . $appendFormFieldNames;
161 $html .= '<input type="hidden" name="' . htmlspecialchars($ucFieldName)
162 . '" value="' . (int)$data['isInlineChildExpanded'] . '" />';
163 } else {
164 // Set additional field for processing for saving
165 $html .= '<input type="hidden" name="cmd' . htmlspecialchars($appendFormFieldNames)
166 . '[delete]" value="1" disabled="disabled" />';
167 if (!$data['isInlineChildExpanded'] && !empty($hiddenField)) {
168 $checked = !empty($record[$hiddenField]) ? ' checked="checked"' : '';
169 $html .= '<input type="checkbox" data-formengine-input-name="data'
170 . htmlspecialchars($appendFormFieldNames)
171 . '[' . htmlspecialchars($hiddenField) . ']" value="1"' . $checked . ' />';
172 $html .= '<input type="input" name="data' . htmlspecialchars($appendFormFieldNames)
173 . '[' . htmlspecialchars($hiddenField) . ']" value="' . htmlspecialchars($record[$hiddenField]) . '" />';
174 }
175 }
176 // If this record should be shown collapsed
177 $class = $data['isInlineChildExpanded'] ? 'panel-visible' : 'panel-collapsed';
178 }
179 if ($inlineConfig['renderFieldsOnly']) {
180 // Render "body" part only
181 $html = $html . $combinationHtml;
182 } else {
183 // Render header row and content (if expanded)
184 if ($data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
185 $class .= ' t3-form-field-container-inline-placeHolder';
186 }
187 if (!empty($hiddenField) && isset($record[$hiddenField]) && (int)$record[$hiddenField]) {
188 $class .= ' t3-form-field-container-inline-hidden';
189 }
190 $class .= ($isNewRecord ? ' inlineIsNewRecord' : '');
191 $html = '
192 <div class="panel panel-default panel-condensed ' . trim($class) . '" id="' . htmlspecialchars($objectId) . '_div">
193 <div class="panel-heading" data-toggle="formengine-inline" id="' . htmlspecialchars($objectId) . '_header" data-expandSingle="' . ($inlineConfig['appearance']['expandSingle'] ? 1 : 0) . '">
194 <div class="form-irre-header">
195 <div class="form-irre-header-cell form-irre-header-icon">
196 <span class="caret"></span>
197 </div>
198 ' . $this->renderForeignRecordHeader($data) . '
199 </div>
200 </div>
201 <div class="panel-collapse" id="' . htmlspecialchars($objectId) . '_fields" data-expandSingle="' . ($inlineConfig['appearance']['expandSingle'] ? 1 : 0) . '" data-returnURL="' . htmlspecialchars(GeneralUtility::getIndpEnv('REQUEST_URI')) . '">' . $html . $combinationHtml . '</div>
202 </div>';
203 }
204
205 $resultArray['html'] = $html;
206 return $resultArray;
207 }
208
209 /**
210 * Render inner child
211 *
212 * @param array $data
213 * @return array Result array
214 */
215 protected function renderChild(array $data)
216 {
217 $domObjectId = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($data['inlineFirstPid']);
218 $data['tabAndInlineStack'][] = [
219 'inline',
220 $domObjectId . '-' . $data['tableName'] . '-' . $data['databaseRow']['uid'],
221 ];
222 // @todo: ugly construct ...
223 $data['inlineData'] = $this->inlineData;
224 $data['renderType'] = 'fullRecordContainer';
225 return $this->nodeFactory->create($data)->render();
226 }
227
228 /**
229 * Render child child
230 *
231 * Render a table with FormEngine, that occurs on an intermediate table but should be editable directly,
232 * so two tables are combined (the intermediate table with attributes and the sub-embedded table).
233 * -> This is a direct embedding over two levels!
234 *
235 * @param array $data
236 * @param string $appendFormFieldNames The [<table>][<uid>] of the parent record (the intermediate table)
237 * @return array Result array
238 */
239 protected function renderCombinationChild(array $data, $appendFormFieldNames)
240 {
241 $childData = $data['combinationChild'];
242 $parentConfig = $data['inlineParentConfig'];
243
244 $resultArray = $this->initializeResultArray();
245
246 // Display Warning FlashMessage if it is not suppressed
247 if (!isset($parentConfig['appearance']['suppressCombinationWarning']) || empty($parentConfig['appearance']['suppressCombinationWarning'])) {
248 $combinationWarningMessage = 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.inline_use_combination';
249 if (!empty($parentConfig['appearance']['overwriteCombinationWarningMessage'])) {
250 $combinationWarningMessage = $parentConfig['appearance']['overwriteCombinationWarningMessage'];
251 }
252 $message = $this->getLanguageService()->sL($combinationWarningMessage);
253 $markup = [];
254 // @TODO: This is not a FlashMessage! The markup must be changed and special CSS
255 // @TODO: should be created, in order to prevent confusion.
256 $markup[] = '<div class="alert alert-warning">';
257 $markup[] = ' <div class="media">';
258 $markup[] = ' <div class="media-left">';
259 $markup[] = ' <span class="fa-stack fa-lg">';
260 $markup[] = ' <i class="fa fa-circle fa-stack-2x"></i>';
261 $markup[] = ' <i class="fa fa-exclamation fa-stack-1x"></i>';
262 $markup[] = ' </span>';
263 $markup[] = ' </div>';
264 $markup[] = ' <div class="media-body">';
265 $markup[] = ' <div class="alert-message">' . htmlspecialchars($message) . '</div>';
266 $markup[] = ' </div>';
267 $markup[] = ' </div>';
268 $markup[] = '</div>';
269 $resultArray['html'] = implode(LF, $markup);
270 }
271
272 $childArray = $this->renderChild($childData);
273 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childArray);
274
275 // If this is a new record, add a pid value to store this record and the pointer value for the intermediate table
276 if ($childData['command'] === 'new') {
277 $comboFormFieldName = 'data[' . $childData['tableName'] . '][' . $childData['databaseRow']['uid'] . '][pid]';
278 $resultArray['html'] .= '<input type="hidden" name="' . htmlspecialchars($comboFormFieldName) . '" value="' . htmlspecialchars($childData['databaseRow']['pid']) . '" />';
279 }
280 // If the foreign_selector field is also responsible for uniqueness, tell the browser the uid of the "other" side of the relation
281 if ($childData['command'] === 'new' || $parentConfig['foreign_unique'] === $parentConfig['foreign_selector']) {
282 $parentFormFieldName = 'data' . $appendFormFieldNames . '[' . $parentConfig['foreign_selector'] . ']';
283 $resultArray['html'] .= '<input type="hidden" name="' . htmlspecialchars($parentFormFieldName) . '" value="' . htmlspecialchars($childData['databaseRow']['uid']) . '" />';
284 }
285
286 return $resultArray;
287 }
288
289 /**
290 * Renders the HTML header for a foreign record, such as the title, toggle-function, drag'n'drop, etc.
291 * Later on the command-icons are inserted here.
292 *
293 * @param array $data Current data
294 * @return string The HTML code of the header
295 */
296 protected function renderForeignRecordHeader(array $data)
297 {
298 $languageService = $this->getLanguageService();
299 $inlineConfig = $data['inlineParentConfig'];
300 $foreignTable = $inlineConfig['foreign_table'];
301 $rec = $data['databaseRow'];
302 // Init:
303 $domObjectId = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($data['inlineFirstPid']);
304 $objectId = $domObjectId . '-' . $foreignTable . '-' . $rec['uid'];
305
306 $recordTitle = $data['recordTitle'];
307 if (!empty($recordTitle)) {
308 // The user function may return HTML, therefore we can't escape it
309 if (empty($data['processedTca']['ctrl']['formattedLabel_userFunc'])) {
310 $recordTitle = BackendUtility::getRecordTitlePrep($recordTitle);
311 }
312 } else {
313 $recordTitle = '<em>[' . htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.no_title')) . ']</em>';
314 }
315
316 $altText = BackendUtility::getRecordIconAltText($rec, $foreignTable);
317
318 $iconImg = '<span title="' . $altText . '" id="' . htmlspecialchars($objectId) . '_icon' . '">' . $this->iconFactory->getIconForRecord($foreignTable, $rec, Icon::SIZE_SMALL)->render() . '</span>';
319 $label = '<span id="' . $objectId . '_label">' . $recordTitle . '</span>';
320 $ctrl = $this->renderForeignRecordHeaderControl($data);
321 $thumbnail = false;
322
323 // Renders a thumbnail for the header
324 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'] && !empty($inlineConfig['appearance']['headerThumbnail']['field'])) {
325 $fieldValue = $rec[$inlineConfig['appearance']['headerThumbnail']['field']];
326 $fileUid = $fieldValue[0]['uid'];
327
328 if (!empty($fileUid)) {
329 try {
330 $fileObject = ResourceFactory::getInstance()->getFileObject($fileUid);
331 } catch (\InvalidArgumentException $e) {
332 $fileObject = null;
333 }
334 if ($fileObject && $fileObject->isMissing()) {
335 $thumbnail .= '<span class="label label-danger">'
336 . htmlspecialchars(static::getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.file_missing'))
337 . '</span>&nbsp;' . htmlspecialchars($fileObject->getName()) . '<br />';
338 } elseif ($fileObject) {
339 $imageSetup = $inlineConfig['appearance']['headerThumbnail'];
340 unset($imageSetup['field']);
341 if (!empty($rec['crop'])) {
342 $imageSetup['crop'] = $rec['crop'];
343 }
344 $imageSetup = array_merge(['width' => '45', 'height' => '45c'], $imageSetup);
345 $processedImage = $fileObject->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, $imageSetup);
346 // Only use a thumbnail if the processing process was successful by checking if image width is set
347 if ($processedImage->getProperty('width')) {
348 $imageUrl = $processedImage->getPublicUrl(true);
349 $thumbnail = '<img src="' . $imageUrl . '" ' .
350 'width="' . $processedImage->getProperty('width') . '" ' .
351 'height="' . $processedImage->getProperty('height') . '" ' .
352 'alt="' . htmlspecialchars($altText) . '" ' .
353 'title="' . htmlspecialchars($altText) . '">';
354 }
355 }
356 }
357 }
358
359 if (!empty($inlineConfig['appearance']['headerThumbnail']['field']) && $thumbnail) {
360 $mediaContainer = '<div class="form-irre-header-cell form-irre-header-thumbnail" id="' . $objectId . '_thumbnailcontainer">' . $thumbnail . '</div>';
361 } else {
362 $mediaContainer = '<div class="form-irre-header-cell form-irre-header-icon" id="' . $objectId . '_iconcontainer">' . $iconImg . '</div>';
363 }
364 $header = $mediaContainer . '
365 <div class="form-irre-header-cell form-irre-header-body">' . $label . '</div>
366 <div class="form-irre-header-cell form-irre-header-control t3js-formengine-irre-control">' . $ctrl . '</div>';
367
368 return $header;
369 }
370
371 /**
372 * Render the control-icons for a record header (create new, sorting, delete, disable/enable).
373 * Most of the parts are copy&paste from TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList and
374 * modified for the JavaScript calls here
375 *
376 * @param array $data Current data
377 * @return string The HTML code with the control-icons
378 */
379 protected function renderForeignRecordHeaderControl(array $data)
380 {
381 $rec = $data['databaseRow'];
382 $inlineConfig = $data['inlineParentConfig'];
383 $foreignTable = $inlineConfig['foreign_table'];
384 $languageService = $this->getLanguageService();
385 $backendUser = $this->getBackendUserAuthentication();
386 // Initialize:
387 $cells = [];
388 $additionalCells = [];
389 $isNewItem = substr($rec['uid'], 0, 3) == 'NEW';
390 $isParentExisting = MathUtility::canBeInterpretedAsInteger($data['inlineParentUid']);
391 $tcaTableCtrl = $GLOBALS['TCA'][$foreignTable]['ctrl'];
392 $tcaTableCols = $GLOBALS['TCA'][$foreignTable]['columns'];
393 $isPagesTable = $foreignTable === 'pages';
394 $isSysFileReferenceTable = $foreignTable === 'sys_file_reference';
395 $enableManualSorting = $tcaTableCtrl['sortby'] || $inlineConfig['MM'] || !$data['isOnSymmetricSide']
396 && $inlineConfig['foreign_sortby'] || $data['isOnSymmetricSide'] && $inlineConfig['symmetric_sortby'];
397 $nameObject = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($data['inlineFirstPid']);
398 $nameObjectFt = $nameObject . '-' . $foreignTable;
399 $nameObjectFtId = $nameObjectFt . '-' . $rec['uid'];
400 $calcPerms = $backendUser->calcPerms(BackendUtility::readPageAccess($rec['pid'], $backendUser->getPagePermsClause(1)));
401 // If the listed table is 'pages' we have to request the permission settings for each page:
402 $localCalcPerms = false;
403 if ($isPagesTable) {
404 $localCalcPerms = $backendUser->calcPerms(BackendUtility::getRecord('pages', $rec['uid']));
405 }
406 // This expresses the edit permissions for this particular element:
407 $permsEdit = $isPagesTable && $localCalcPerms & Permission::PAGE_EDIT || !$isPagesTable && $calcPerms & Permission::CONTENT_EDIT;
408 // Controls: Defines which controls should be shown
409 $enabledControls = $inlineConfig['appearance']['enabledControls'];
410 // Hook: Can disable/enable single controls for specific child records:
411 foreach ($this->hookObjects as $hookObj) {
412 /** @var InlineElementHookInterface $hookObj */
413 $hookObj->renderForeignRecordHeaderControl_preProcess($data['inlineParentUid'], $foreignTable, $rec, $inlineConfig, $data['isInlineDefaultLanguageRecordInLocalizedParentContext'], $enabledControls);
414 }
415 if ($data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
416 $cells['localize.isLocalizable'] = '<span title="' . htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:localize.isLocalizable')) . '">'
417 . $this->iconFactory->getIcon('actions-edit-localize-status-low', Icon::SIZE_SMALL)->render()
418 . '</span>';
419 }
420 // "Info": (All records)
421 // @todo: hardcoded sys_file!
422 if ($rec['table_local'] === 'sys_file') {
423 $uid = $rec['uid_local'][0]['uid'];
424 $table = '_FILE';
425 } else {
426 $uid = $rec['uid'];
427 $table = $foreignTable;
428 }
429 if ($enabledControls['info'] && !$isNewItem) {
430 $cells['info'] = '
431 <a class="btn btn-default" href="#" onclick="' . htmlspecialchars(('top.launchView(' . GeneralUtility::quoteJSvalue($table) . ', ' . GeneralUtility::quoteJSvalue($uid) . '); return false;')) . '" title="' . htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:showInfo')) . '">
432 ' . $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL)->render() . '
433 </a>';
434 }
435 // If the table is NOT a read-only table, then show these links:
436 if (!$tcaTableCtrl['readOnly'] && !$data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
437 // "New record after" link (ONLY if the records in the table are sorted by a "sortby"-row or if default values can depend on previous record):
438 if ($enabledControls['new'] && ($enableManualSorting || $tcaTableCtrl['useColumnsForDefaultValues'])) {
439 if (!$isPagesTable && $calcPerms & Permission::CONTENT_EDIT || $isPagesTable && $calcPerms & Permission::PAGE_NEW) {
440 $onClick = 'return inline.createNewRecord(' . GeneralUtility::quoteJSvalue($nameObjectFt) . ',' . GeneralUtility::quoteJSvalue($rec['uid']) . ')';
441 $style = '';
442 if ($inlineConfig['inline']['inlineNewButtonStyle']) {
443 $style = ' style="' . $inlineConfig['inline']['inlineNewButtonStyle'] . '"';
444 }
445 $cells['new'] = '
446 <a class="btn btn-default inlineNewButton ' . $this->inlineData['config'][$nameObject]['md5'] . '" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . htmlspecialchars($languageService->sL(('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:new' . ($isPagesTable ? 'Page' : 'Record')))) . '" ' . $style . '>
447 ' . $this->iconFactory->getIcon('actions-' . ($isPagesTable ? 'page' : 'document') . '-new', Icon::SIZE_SMALL)->render() . '
448 </a>';
449 }
450 }
451 // "Up/Down" links
452 if ($enabledControls['sort'] && $permsEdit && $enableManualSorting) {
453 // Up
454 $onClick = 'return inline.changeSorting(' . GeneralUtility::quoteJSvalue($nameObjectFtId) . ', \'1\')';
455 $style = $inlineConfig['inline']['first'] == $rec['uid'] ? 'style="visibility: hidden;"' : '';
456 $cells['sort.up'] = '
457 <a class="btn btn-default sortingUp" href="#" onclick="' . htmlspecialchars($onClick) . '" ' . $style . ' title="' . htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:moveUp')) . '">
458 ' . $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render() . '
459 </a>';
460 // Down
461 $onClick = 'return inline.changeSorting(' . GeneralUtility::quoteJSvalue($nameObjectFtId) . ', \'-1\')';
462 $style = $inlineConfig['inline']['last'] == $rec['uid'] ? 'style="visibility: hidden;"' : '';
463 $cells['sort.down'] = '
464 <a class="btn btn-default sortingDown" href="#" onclick="' . htmlspecialchars($onClick) . '" ' . $style . ' title="' . htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:moveDown')) . '">
465 ' . $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render() . '
466 </a>';
467 }
468 // "Edit" link:
469 if (($rec['table_local'] === 'sys_file') && !$isNewItem) {
470 $sys_language_uid = 0;
471 if (!empty($rec['sys_language_uid'])) {
472 $sys_language_uid = $rec['sys_language_uid'][0];
473 }
474 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
475 ->getQueryBuilderForTable('sys_file_metadata');
476 $recordInDatabase = $queryBuilder
477 ->select('uid')
478 ->from('sys_file_metadata')
479 ->where(
480 $queryBuilder->expr()->eq(
481 'file',
482 $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
483 ),
484 $queryBuilder->expr()->eq(
485 'sys_language_uid',
486 $queryBuilder->createNamedParameter($sys_language_uid, \PDO::PARAM_INT)
487 )
488 )
489 ->setMaxResults(1)
490 ->execute()
491 ->fetch();
492 if ($backendUser->check('tables_modify', 'sys_file_metadata')) {
493 $url = BackendUtility::getModuleUrl('record_edit', [
494 'edit[sys_file_metadata][' . (int)$recordInDatabase['uid'] . ']' => 'edit',
495 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
496 ]);
497 $title = $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.editMetadata');
498 $cells['editmetadata'] = '
499 <a class="btn btn-default" href="' . htmlspecialchars($url) . '" title="' . htmlspecialchars($title) . '">
500 ' . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '
501 </a>';
502 }
503 }
504 // "Delete" link:
505 if ($enabledControls['delete'] && ($isPagesTable && $localCalcPerms & Permission::PAGE_DELETE
506 || !$isPagesTable && $calcPerms & Permission::CONTENT_EDIT
507 || $isSysFileReferenceTable && $calcPerms & Permission::PAGE_EDIT)
508 ) {
509 $title = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:delete'));
510 $icon = $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render();
511 $cells['delete'] = '<a href="#" class="btn btn-default t3js-editform-delete-inline-record" data-objectid="' . htmlspecialchars($nameObjectFtId) . '" title="' . $title . '">' . $icon . '</a>';
512 }
513
514 // "Hide/Unhide" links:
515 $hiddenField = $tcaTableCtrl['enablecolumns']['disabled'];
516 if ($enabledControls['hide'] && $permsEdit && $hiddenField && $tcaTableCols[$hiddenField] && (!$tcaTableCols[$hiddenField]['exclude'] || $backendUser->check('non_exclude_fields', $foreignTable . ':' . $hiddenField))) {
517 $onClick = 'return inline.enableDisableRecord(' . GeneralUtility::quoteJSvalue($nameObjectFtId) . ',' .
518 GeneralUtility::quoteJSvalue($hiddenField) . ')';
519 $className = 't3js-' . $nameObjectFtId . '_disabled';
520 if ($rec[$hiddenField]) {
521 $title = htmlspecialchars($languageService->sL(('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:unHide' . ($isPagesTable ? 'Page' : ''))));
522 $cells['hide.unhide'] = '
523 <a class="btn btn-default hiddenHandle ' . $className . '" href="#" onclick="'
524 . htmlspecialchars($onClick) . '"' . 'title="' . $title . '">' .
525 $this->iconFactory->getIcon('actions-edit-unhide', Icon::SIZE_SMALL)->render() . '
526 </a>';
527 } else {
528 $title = htmlspecialchars($languageService->sL(('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:hide' . ($isPagesTable ? 'Page' : ''))));
529 $cells['hide.hide'] = '
530 <a class="btn btn-default hiddenHandle ' . $className . '" href="#" onclick="'
531 . htmlspecialchars($onClick) . '"' . 'title="' . $title . '">' .
532 $this->iconFactory->getIcon('actions-edit-hide', Icon::SIZE_SMALL)->render() . '
533 </a>';
534 }
535 }
536 // Drag&Drop Sorting: Sortable handler for script.aculo.us
537 if ($enabledControls['dragdrop'] && $permsEdit && $enableManualSorting && $inlineConfig['appearance']['useSortable']) {
538 $additionalCells['dragdrop'] = '
539 <span class="btn btn-default sortableHandle" data-id="' . htmlspecialchars($rec['uid']) . '" title="' . htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.move')) . '">
540 ' . $this->iconFactory->getIcon('actions-move-move', Icon::SIZE_SMALL)->render() . '
541 </span>';
542 }
543 } elseif ($data['isInlineDefaultLanguageRecordInLocalizedParentContext'] && $isParentExisting) {
544 if ($enabledControls['localize'] && $data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
545 $onClick = 'inline.synchronizeLocalizeRecords(' . GeneralUtility::quoteJSvalue($nameObjectFt) . ', ' . GeneralUtility::quoteJSvalue($rec['uid']) . ');';
546 $cells['localize'] = '
547 <a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:localize')) . '">
548 ' . $this->iconFactory->getIcon('actions-document-localize', Icon::SIZE_SMALL)->render() . '
549 </a>';
550 }
551 }
552 // If the record is edit-locked by another user, we will show a little warning sign:
553 if ($lockInfo = BackendUtility::isRecordLocked($foreignTable, $rec['uid'])) {
554 $cells['locked'] = '
555 <a class="btn btn-default" href="#" onclick="alert(' . GeneralUtility::quoteJSvalue($lockInfo['msg']) . ');return false;">
556 ' . '<span title="' . htmlspecialchars($lockInfo['msg']) . '">' . $this->iconFactory->getIcon('status-warning-in-use', Icon::SIZE_SMALL)->render() . '</span>' . '
557 </a>';
558 }
559 // Hook: Post-processing of single controls for specific child records:
560 foreach ($this->hookObjects as $hookObj) {
561 $hookObj->renderForeignRecordHeaderControl_postProcess($data['inlineParentUid'], $foreignTable, $rec, $inlineConfig, $data['isInlineDefaultLanguageRecordInLocalizedParentContext'], $cells);
562 }
563
564 $out = '';
565 if (!empty($cells)) {
566 $out .= ' <div class="btn-group btn-group-sm" role="group">' . implode('', $cells) . '</div>';
567 }
568 if (!empty($additionalCells)) {
569 $out .= ' <div class="btn-group btn-group-sm" role="group">' . implode('', $additionalCells) . '</div>';
570 }
571 return $out;
572 }
573
574 /**
575 * Normalize a relation "uid" published by transferData, like "1|Company%201"
576 *
577 * @param string $string A transferData reference string, containing the uid
578 * @return string The normalized uid
579 */
580 protected function normalizeUid($string)
581 {
582 $parts = explode('|', $string);
583 return $parts[0];
584 }
585
586 /**
587 * Initialized the hook objects for this class.
588 * Each hook object has to implement the interface
589 * \TYPO3\CMS\Backend\Form\Element\InlineElementHookInterface
590 *
591 * @throws \UnexpectedValueException
592 * @return void
593 */
594 protected function initHookObjects()
595 {
596 $this->hookObjects = [];
597 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms_inline.php']['tceformsInlineHook'])) {
598 $tceformsInlineHook = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms_inline.php']['tceformsInlineHook'];
599 if (is_array($tceformsInlineHook)) {
600 foreach ($tceformsInlineHook as $classData) {
601 $processObject = GeneralUtility::getUserObj($classData);
602 if (!$processObject instanceof InlineElementHookInterface) {
603 throw new \UnexpectedValueException($classData . ' must implement interface ' . InlineElementHookInterface::class, 1202072000);
604 }
605 $this->hookObjects[] = $processObject;
606 }
607 }
608 }
609 }
610
611 /**
612 * @return BackendUserAuthentication
613 */
614 protected function getBackendUserAuthentication()
615 {
616 return $GLOBALS['BE_USER'];
617 }
618
619 /**
620 * @return LanguageService
621 */
622 protected function getLanguageService()
623 {
624 return $GLOBALS['LANG'];
625 }
626 }