Passed
Branch master (6c65a4)
by Christian
27:15 queued 11:09
created

InlineRecordContainer::renderChild()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
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\Localization\LanguageService;
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
33
/**
34
 * Render a single inline record relation.
35
 *
36
 * This container is called by InlineControlContainer to render single existing records.
37
 * Furthermore it is called by FormEngine for an incoming ajax request to expand an existing record
38
 * or to create a new one.
39
 *
40
 * This container creates the outer HTML of single inline records - eg. drag and drop and delete buttons.
41
 * For rendering of the record itself processing is handed over to FullRecordContainer.
42
 */
43
class InlineRecordContainer extends AbstractContainer
44
{
45
    /**
46
     * Inline data array used for JSON output
47
     *
48
     * @var array
49
     */
50
    protected $inlineData = [];
51
52
    /**
53
     * @var InlineStackProcessor
54
     */
55
    protected $inlineStackProcessor;
56
57
    /**
58
     * Array containing instances of hook classes called once for IRRE objects
59
     *
60
     * @var array
61
     */
62
    protected $hookObjects = [];
63
64
    /**
65
     * @var IconFactory
66
     */
67
    protected $iconFactory;
68
69
    /**
70
     * Default constructor
71
     *
72
     * @param NodeFactory $nodeFactory
73
     * @param array $data
74
     */
75
    public function __construct(NodeFactory $nodeFactory, array $data)
76
    {
77
        parent::__construct($nodeFactory, $data);
78
        $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
79
        $this->inlineStackProcessor = GeneralUtility::makeInstance(InlineStackProcessor::class);
80
        $this->initHookObjects();
81
    }
82
83
    /**
84
     * Entry method
85
     *
86
     * @return array As defined in initializeResultArray() of AbstractNode
87
     * @throws AccessDeniedContentEditException
88
     */
89
    public function render()
90
    {
91
        $data = $this->data;
92
        $this->inlineData = $data['inlineData'];
93
94
        $inlineStackProcessor = $this->inlineStackProcessor;
95
        $inlineStackProcessor->initializeByGivenStructure($data['inlineStructure']);
96
97
        $record = $data['databaseRow'];
98
        $inlineConfig = $data['inlineParentConfig'];
99
        $foreignTable = $inlineConfig['foreign_table'];
100
101
        $resultArray = $this->initializeResultArray();
102
103
        // Send a mapping information to the browser via JSON:
104
        // e.g. data[<curTable>][<curId>][<curField>] => data-<pid>-<parentTable>-<parentId>-<parentField>-<curTable>-<curId>-<curField>
105
        $formPrefix = $inlineStackProcessor->getCurrentStructureFormPrefix();
106
        $domObjectId = $inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($data['inlineFirstPid']);
107
        $this->inlineData['map'][$formPrefix] = $domObjectId;
108
109
        $resultArray['inlineData'] = $this->inlineData;
110
111
        // If there is a selector field, normalize it:
112
        if (!empty($inlineConfig['foreign_selector'])) {
113
            $foreign_selector = $inlineConfig['foreign_selector'];
114
            $valueToNormalize = $record[$foreign_selector];
115
            if (is_array($record[$foreign_selector])) {
116
                // @todo: this can be kicked again if always prepared rows are handled here
117
                $valueToNormalize = implode(',', $record[$foreign_selector]);
118
            }
119
            $record[$foreign_selector] = $this->normalizeUid($valueToNormalize);
120
        }
121
122
        // Get the current naming scheme for DOM name/id attributes:
123
        $appendFormFieldNames = '[' . $foreignTable . '][' . $record['uid'] . ']';
124
        $objectId = $domObjectId . '-' . $foreignTable . '-' . $record['uid'];
125
        $class = '';
126
        $html = '';
127
        $combinationHtml = '';
128
        $isNewRecord = $data['command'] === 'new';
129
        $hiddenField = '';
130
        if (isset($data['processedTca']['ctrl']['enablecolumns']['disabled'])) {
131
            $hiddenField = $data['processedTca']['ctrl']['enablecolumns']['disabled'];
132
        }
133
        if (!$data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
134
            if ($isNewRecord || $data['isInlineChildExpanded']) {
135
                // Render full content ONLY IF this is an AJAX request, a new record, or the record is not collapsed
136
                $combinationHtml = '';
137
                if (isset($data['combinationChild'])) {
138
                    $combinationChild = $this->renderCombinationChild($data, $appendFormFieldNames);
139
                    $combinationHtml = $combinationChild['html'];
140
                    $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $combinationChild, false);
141
                }
142
                $childArray = $this->renderChild($data);
143
                $html = $childArray['html'];
144
                $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childArray, false);
145
            } else {
146
                // This string is the marker for the JS-function to check if the full content has already been loaded
147
                $html = '<!--notloaded-->';
148
            }
149
            if ($isNewRecord) {
150
                // Add pid of record as hidden field
151
                $html .= '<input type="hidden" name="data' . htmlspecialchars($appendFormFieldNames)
152
                    . '[pid]" value="' . htmlspecialchars($record['pid']) . '"/>';
153
                // Tell DataHandler this record is expanded
154
                $ucFieldName = 'uc[inlineView]'
155
                    . '[' . $data['inlineTopMostParentTableName'] . ']'
156
                    . '[' . $data['inlineTopMostParentUid'] . ']'
157
                    . $appendFormFieldNames;
158
                $html .= '<input type="hidden" name="' . htmlspecialchars($ucFieldName)
159
                    . '" value="' . (int)$data['isInlineChildExpanded'] . '" />';
160
            } else {
161
                // Set additional field for processing for saving
162
                $html .= '<input type="hidden" name="cmd' . htmlspecialchars($appendFormFieldNames)
163
                    . '[delete]" value="1" disabled="disabled" />';
164
                if (!$data['isInlineChildExpanded'] && !empty($hiddenField)) {
165
                    $checked = !empty($record[$hiddenField]) ? ' checked="checked"' : '';
166
                    $html .= '<input type="checkbox" data-formengine-input-name="data'
167
                        . htmlspecialchars($appendFormFieldNames)
168
                        . '[' . htmlspecialchars($hiddenField) . ']" value="1"' . $checked . ' />';
169
                    $html .= '<input type="input" name="data' . htmlspecialchars($appendFormFieldNames)
170
                        . '[' . htmlspecialchars($hiddenField) . ']" value="' . htmlspecialchars($record[$hiddenField]) . '" />';
171
                }
172
            }
173
            // If this record should be shown collapsed
174
            $class = $data['isInlineChildExpanded'] ? 'panel-visible' : 'panel-collapsed';
175
        }
176
        if ($inlineConfig['renderFieldsOnly']) {
177
            // Render "body" part only
178
            $html = $html . $combinationHtml;
179
        } else {
180
            // Render header row and content (if expanded)
181
            if ($data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
182
                $class .= ' t3-form-field-container-inline-placeHolder';
183
            }
184
            if (!empty($hiddenField) && isset($record[$hiddenField]) && (int)$record[$hiddenField]) {
185
                $class .= ' t3-form-field-container-inline-hidden';
186
            }
187
            $class .= ($isNewRecord ? ' inlineIsNewRecord' : '');
188
            $html = '
189
				<div class="panel panel-default panel-condensed ' . trim($class) . '" id="' . htmlspecialchars($objectId) . '_div">
190
					<div class="panel-heading" data-toggle="formengine-inline" id="' . htmlspecialchars($objectId) . '_header" data-expandSingle="' . ($inlineConfig['appearance']['expandSingle'] ? 1 : 0) . '">
191
						<div class="form-irre-header">
192
							<div class="form-irre-header-cell form-irre-header-icon">
193
								<span class="caret"></span>
194
							</div>
195
							' . $this->renderForeignRecordHeader($data) . '
196
						</div>
197
					</div>
198
					<div class="panel-collapse" id="' . htmlspecialchars($objectId) . '_fields">' . $html . $combinationHtml . '</div>
199
				</div>';
200
        }
201
202
        $resultArray['html'] = $html;
203
        return $resultArray;
204
    }
205
206
    /**
207
     * Render inner child
208
     *
209
     * @param array $data
210
     * @return array Result array
211
     */
212
    protected function renderChild(array $data)
213
    {
214
        $domObjectId = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($data['inlineFirstPid']);
215
        $data['tabAndInlineStack'][] = [
216
            'inline',
217
            $domObjectId . '-' . $data['tableName'] . '-' . $data['databaseRow']['uid'],
218
        ];
219
        // @todo: ugly construct ...
220
        $data['inlineData'] = $this->inlineData;
221
        $data['renderType'] = 'fullRecordContainer';
222
        return $this->nodeFactory->create($data)->render();
223
    }
224
225
    /**
226
     * Render child child
227
     *
228
     * Render a table with FormEngine, that occurs on an intermediate table but should be editable directly,
229
     * so two tables are combined (the intermediate table with attributes and the sub-embedded table).
230
     * -> This is a direct embedding over two levels!
231
     *
232
     * @param array $data
233
     * @param string $appendFormFieldNames The [<table>][<uid>] of the parent record (the intermediate table)
234
     * @return array Result array
235
     */
236
    protected function renderCombinationChild(array $data, $appendFormFieldNames)
237
    {
238
        $childData = $data['combinationChild'];
239
        $parentConfig = $data['inlineParentConfig'];
240
241
        $resultArray = $this->initializeResultArray();
242
243
        // Display Warning FlashMessage if it is not suppressed
244
        if (!isset($parentConfig['appearance']['suppressCombinationWarning']) || empty($parentConfig['appearance']['suppressCombinationWarning'])) {
245
            $combinationWarningMessage = 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.inline_use_combination';
246
            if (!empty($parentConfig['appearance']['overwriteCombinationWarningMessage'])) {
247
                $combinationWarningMessage = $parentConfig['appearance']['overwriteCombinationWarningMessage'];
248
            }
249
            $message = $this->getLanguageService()->sL($combinationWarningMessage);
250
            $markup = [];
251
            // @TODO: This is not a FlashMessage! The markup must be changed and special CSS
252
            // @TODO: should be created, in order to prevent confusion.
253
            $markup[] = '<div class="alert alert-warning">';
254
            $markup[] = '    <div class="media">';
255
            $markup[] = '        <div class="media-left">';
256
            $markup[] = '            <span class="fa-stack fa-lg">';
257
            $markup[] = '                <i class="fa fa-circle fa-stack-2x"></i>';
258
            $markup[] = '                <i class="fa fa-exclamation fa-stack-1x"></i>';
259
            $markup[] = '            </span>';
260
            $markup[] = '        </div>';
261
            $markup[] = '        <div class="media-body">';
262
            $markup[] = '            <div class="alert-message">' . htmlspecialchars($message) . '</div>';
263
            $markup[] = '        </div>';
264
            $markup[] = '    </div>';
265
            $markup[] = '</div>';
266
            $resultArray['html'] = implode(LF, $markup);
267
        }
268
269
        $childArray = $this->renderChild($childData);
270
        $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childArray);
271
272
        // If this is a new record, add a pid value to store this record and the pointer value for the intermediate table
273
        if ($childData['command'] === 'new') {
274
            $comboFormFieldName = 'data[' . $childData['tableName'] . '][' . $childData['databaseRow']['uid'] . '][pid]';
275
            $resultArray['html'] .= '<input type="hidden" name="' . htmlspecialchars($comboFormFieldName) . '" value="' . htmlspecialchars($childData['databaseRow']['pid']) . '" />';
276
        }
277
        // If the foreign_selector field is also responsible for uniqueness, tell the browser the uid of the "other" side of the relation
278
        if ($childData['command'] === 'new' || $parentConfig['foreign_unique'] === $parentConfig['foreign_selector']) {
279
            $parentFormFieldName = 'data' . $appendFormFieldNames . '[' . $parentConfig['foreign_selector'] . ']';
280
            $resultArray['html'] .= '<input type="hidden" name="' . htmlspecialchars($parentFormFieldName) . '" value="' . htmlspecialchars($childData['databaseRow']['uid']) . '" />';
281
        }
282
283
        return $resultArray;
284
    }
285
286
    /**
287
     * Renders the HTML header for a foreign record, such as the title, toggle-function, drag'n'drop, etc.
288
     * Later on the command-icons are inserted here.
289
     *
290
     * @param array $data Current data
291
     * @return string The HTML code of the header
292
     */
293
    protected function renderForeignRecordHeader(array $data)
294
    {
295
        $languageService = $this->getLanguageService();
296
        $inlineConfig = $data['inlineParentConfig'];
297
        $foreignTable = $inlineConfig['foreign_table'];
298
        $rec = $data['databaseRow'];
299
        // Init:
300
        $domObjectId = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($data['inlineFirstPid']);
301
        $objectId = $domObjectId . '-' . $foreignTable . '-' . $rec['uid'];
302
303
        $recordTitle = $data['recordTitle'];
304
        if (!empty($recordTitle)) {
305
            // The user function may return HTML, therefore we can't escape it
306
            if (empty($data['processedTca']['ctrl']['formattedLabel_userFunc'])) {
307
                $recordTitle = BackendUtility::getRecordTitlePrep($recordTitle);
308
            }
309
        } else {
310
            $recordTitle = '<em>[' . htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.no_title')) . ']</em>';
311
        }
312
313
        $altText = BackendUtility::getRecordIconAltText($rec, $foreignTable);
314
315
        $iconImg = '<span title="' . $altText . '" id="' . htmlspecialchars($objectId) . '_icon' . '">' . $this->iconFactory->getIconForRecord($foreignTable, $rec, Icon::SIZE_SMALL)->render() . '</span>';
316
        $label = '<span id="' . $objectId . '_label">' . $recordTitle . '</span>';
317
        $ctrl = $this->renderForeignRecordHeaderControl($data);
318
        $thumbnail = false;
319
320
        // Renders a thumbnail for the header
321
        if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'] && !empty($inlineConfig['appearance']['headerThumbnail']['field'])) {
322
            $fieldValue = $rec[$inlineConfig['appearance']['headerThumbnail']['field']];
323
            $fileUid = $fieldValue[0]['uid'];
324
325
            if (!empty($fileUid)) {
326
                try {
327
                    $fileObject = ResourceFactory::getInstance()->getFileObject($fileUid);
328
                } catch (\InvalidArgumentException $e) {
329
                    $fileObject = null;
330
                }
331
                if ($fileObject && $fileObject->isMissing()) {
332
                    $thumbnail .= '<span class="label label-danger">'
333
                        . htmlspecialchars(static::getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.file_missing'))
0 ignored issues
show
Bug Best Practice introduced by
The method TYPO3\CMS\Backend\Form\C...r::getLanguageService() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

333
                        . htmlspecialchars(static::/** @scrutinizer ignore-call */ getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.file_missing'))
Loading history...
334
                        . '</span>&nbsp;' . htmlspecialchars($fileObject->getName()) . '<br />';
335
                } elseif ($fileObject) {
336
                    $imageSetup = $inlineConfig['appearance']['headerThumbnail'];
337
                    unset($imageSetup['field']);
338
                    if (!empty($rec['crop'])) {
339
                        $imageSetup['crop'] = $rec['crop'];
340
                    }
341
                    $imageSetup = array_merge(['width' => '45', 'height' => '45c'], $imageSetup);
342
343
                    if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails']
344
                        && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileObject->getExtension())) {
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
                    } else {
356
                        $thumbnail = '';
357
                    }
358
                }
359
            }
360
        }
361
362
        if (!empty($inlineConfig['appearance']['headerThumbnail']['field']) && $thumbnail) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $thumbnail of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
363
            $mediaContainer = '<div class="form-irre-header-cell form-irre-header-thumbnail" id="' . $objectId . '_thumbnailcontainer">' . $thumbnail . '</div>';
364
        } else {
365
            $mediaContainer = '<div class="form-irre-header-cell form-irre-header-icon" id="' . $objectId . '_iconcontainer">' . $iconImg . '</div>';
366
        }
367
        $header = $mediaContainer . '
368
				<div class="form-irre-header-cell form-irre-header-body">' . $label . '</div>
369
				<div class="form-irre-header-cell form-irre-header-control t3js-formengine-irre-control">' . $ctrl . '</div>';
370
371
        return $header;
372
    }
373
374
    /**
375
     * Render the control-icons for a record header (create new, sorting, delete, disable/enable).
376
     * Most of the parts are copy&paste from TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList and
377
     * modified for the JavaScript calls here
378
     *
379
     * @param array $data Current data
380
     * @return string The HTML code with the control-icons
381
     */
382
    protected function renderForeignRecordHeaderControl(array $data)
383
    {
384
        $rec = $data['databaseRow'];
385
        $inlineConfig = $data['inlineParentConfig'];
386
        $foreignTable = $inlineConfig['foreign_table'];
387
        $languageService = $this->getLanguageService();
388
        $backendUser = $this->getBackendUserAuthentication();
389
        // Initialize:
390
        $cells = [
391
            'edit' => '',
392
            'hide' => '',
393
            'delete' => '',
394
            'info' => '',
395
            'new' => '',
396
            'sort.up' => '',
397
            'sort.down' => '',
398
            'dragdrop' => '',
399
            'localize' => '',
400
            'locked' => '',
401
        ];
402
        $isNewItem = substr($rec['uid'], 0, 3) === 'NEW';
403
        $isParentExisting = MathUtility::canBeInterpretedAsInteger($data['inlineParentUid']);
404
        $tcaTableCtrl = $GLOBALS['TCA'][$foreignTable]['ctrl'];
405
        $tcaTableCols = $GLOBALS['TCA'][$foreignTable]['columns'];
406
        $isPagesTable = $foreignTable === 'pages';
407
        $isSysFileReferenceTable = $foreignTable === 'sys_file_reference';
408
        $enableManualSorting = $tcaTableCtrl['sortby'] || $inlineConfig['MM'] || !$data['isOnSymmetricSide']
409
            && $inlineConfig['foreign_sortby'] || $data['isOnSymmetricSide'] && $inlineConfig['symmetric_sortby'];
410
        $nameObject = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($data['inlineFirstPid']);
411
        $nameObjectFt = $nameObject . '-' . $foreignTable;
412
        $nameObjectFtId = $nameObjectFt . '-' . $rec['uid'];
413
        $calcPerms = $backendUser->calcPerms(BackendUtility::readPageAccess($rec['pid'], $backendUser->getPagePermsClause(Permission::PAGE_SHOW)));
414
        // If the listed table is 'pages' we have to request the permission settings for each page:
415
        $localCalcPerms = false;
416
        if ($isPagesTable) {
417
            $localCalcPerms = $backendUser->calcPerms(BackendUtility::getRecord('pages', $rec['uid']));
418
        }
419
        // This expresses the edit permissions for this particular element:
420
        $permsEdit = $isPagesTable && $localCalcPerms & Permission::PAGE_EDIT || !$isPagesTable && $calcPerms & Permission::CONTENT_EDIT;
421
        // Controls: Defines which controls should be shown
422
        $enabledControls = $inlineConfig['appearance']['enabledControls'];
423
        // Hook: Can disable/enable single controls for specific child records:
424
        foreach ($this->hookObjects as $hookObj) {
425
            /** @var InlineElementHookInterface $hookObj */
426
            $hookObj->renderForeignRecordHeaderControl_preProcess($data['inlineParentUid'], $foreignTable, $rec, $inlineConfig, $data['isInlineDefaultLanguageRecordInLocalizedParentContext'], $enabledControls);
427
        }
428
        if ($data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
429
            $cells['localize'] = '<span title="' . htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:localize.isLocalizable')) . '">
430
                    ' . $this->iconFactory->getIcon('actions-edit-localize-status-low', Icon::SIZE_SMALL)->render() . '
431
                </span>';
432
        }
433
        // "Info": (All records)
434
        // @todo: hardcoded sys_file!
435
        if ($rec['table_local'] === 'sys_file') {
436
            $uid = $rec['uid_local'][0]['uid'];
437
            $table = '_FILE';
438
        } else {
439
            $uid = $rec['uid'];
440
            $table = $foreignTable;
441
        }
442
        if ($enabledControls['info']) {
443
            if ($isNewItem) {
444
                $cells['info'] = '<span class="btn btn-default disabled">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
445
            } else {
446
                $cells['info'] = '
447
				<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')) . '">
448
					' . $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL)->render() . '
449
				</a>';
450
            }
451
        }
452
        // If the table is NOT a read-only table, then show these links:
453
        if (!$tcaTableCtrl['readOnly'] && !$data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
454
            // "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):
455
            if ($enabledControls['new'] && ($enableManualSorting || $tcaTableCtrl['useColumnsForDefaultValues'])) {
456
                if (!$isPagesTable && $calcPerms & Permission::CONTENT_EDIT || $isPagesTable && $calcPerms & Permission::PAGE_NEW) {
457
                    $onClick = 'return inline.createNewRecord(' . GeneralUtility::quoteJSvalue($nameObjectFt) . ',' . GeneralUtility::quoteJSvalue($rec['uid']) . ')';
458
                    $style = '';
459
                    if ($inlineConfig['inline']['inlineNewButtonStyle']) {
460
                        $style = ' style="' . $inlineConfig['inline']['inlineNewButtonStyle'] . '"';
461
                    }
462
                    $cells['new'] = '
463
                        <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 . '>
464
                            ' . $this->iconFactory->getIcon('actions-' . ($isPagesTable ? 'page-new' : 'add'), Icon::SIZE_SMALL)->render() . '
465
                        </a>';
466
                }
467
            }
468
            // "Up/Down" links
469
            if ($enabledControls['sort'] && $permsEdit && $enableManualSorting) {
470
                // Up
471
                $onClick = 'return inline.changeSorting(' . GeneralUtility::quoteJSvalue($nameObjectFtId) . ', \'1\')';
472
                $icon = 'actions-move-up';
473
                $class = '';
474
                if ($inlineConfig['inline']['first'] == $rec['uid']) {
475
                    $class = ' disabled';
476
                    $icon = 'empty-empty';
477
                }
478
                $cells['sort.up'] = '
479
                    <a class="btn btn-default sortingUp' . $class . '" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:moveUp')) . '">
480
                        ' . $this->iconFactory->getIcon($icon, Icon::SIZE_SMALL)->render() . '
481
                    </a>';
482
                // Down
483
                $onClick = 'return inline.changeSorting(' . GeneralUtility::quoteJSvalue($nameObjectFtId) . ', \'-1\')';
484
                $icon = 'actions-move-down';
485
                $class = '';
486
                if ($inlineConfig['inline']['last'] == $rec['uid']) {
487
                    $class = ' disabled';
488
                    $icon = 'empty-empty';
489
                }
490
491
                $cells['sort.down'] = '
492
                    <a class="btn btn-default sortingDown' . $class . '" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:moveDown')) . '">
493
                        ' . $this->iconFactory->getIcon($icon, Icon::SIZE_SMALL)->render() . '
494
                    </a>';
495
            }
496
            // "Edit" link:
497
            if (($rec['table_local'] === 'sys_file') && !$isNewItem && $backendUser->check('tables_modify', 'sys_file_metadata')) {
498
                $sys_language_uid = 0;
499
                if (!empty($rec['sys_language_uid'])) {
500
                    $sys_language_uid = $rec['sys_language_uid'][0];
501
                }
502
                $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
503
                    ->getQueryBuilderForTable('sys_file_metadata');
504
                $recordInDatabase = $queryBuilder
505
                    ->select('uid')
506
                    ->from('sys_file_metadata')
507
                    ->where(
508
                        $queryBuilder->expr()->eq(
509
                            'file',
510
                            $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
511
                        ),
512
                        $queryBuilder->expr()->eq(
513
                            'sys_language_uid',
514
                            $queryBuilder->createNamedParameter($sys_language_uid, \PDO::PARAM_INT)
515
                        )
516
                    )
517
                    ->setMaxResults(1)
518
                    ->execute()
519
                    ->fetch();
520
                if (!empty($recordInDatabase)) {
521
                    $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
522
                    $url = (string)$uriBuilder->buildUriFromRoute('record_edit', [
523
                        'edit[sys_file_metadata][' . (int)$recordInDatabase['uid'] . ']' => 'edit',
524
                        'returnUrl' => $this->data['returnUrl']
525
                    ]);
526
                    $title = $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.editMetadata');
527
                    $cells['edit'] = '
528
                        <a class="btn btn-default" href="' . htmlspecialchars($url) . '" title="' . htmlspecialchars($title) . '">
529
                            ' . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '
530
                        </a>';
531
                }
532
            }
533
            // "Delete" link:
534
            if ($enabledControls['delete'] && ($isPagesTable && $localCalcPerms & Permission::PAGE_DELETE
535
                    || !$isPagesTable && $calcPerms & Permission::CONTENT_EDIT
536
                    || $isSysFileReferenceTable && $calcPerms & Permission::PAGE_EDIT)
537
            ) {
538
                $title = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:delete'));
539
                $icon = $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render();
540
                $cells['delete'] = '<a href="#" class="btn btn-default t3js-editform-delete-inline-record" data-objectid="' . htmlspecialchars($nameObjectFtId) . '" title="' . $title . '">' . $icon . '</a>';
541
            }
542
543
            // "Hide/Unhide" links:
544
            $hiddenField = $tcaTableCtrl['enablecolumns']['disabled'];
545
            if ($enabledControls['hide'] && $permsEdit && $hiddenField && $tcaTableCols[$hiddenField] && (!$tcaTableCols[$hiddenField]['exclude'] || $backendUser->check('non_exclude_fields', $foreignTable . ':' . $hiddenField))) {
546
                $onClick = 'return inline.enableDisableRecord(' . GeneralUtility::quoteJSvalue($nameObjectFtId) . ',' .
547
                    GeneralUtility::quoteJSvalue($hiddenField) . ')';
548
                $className = 't3js-' . $nameObjectFtId . '_disabled';
549
                if ($rec[$hiddenField]) {
550
                    $title = htmlspecialchars($languageService->sL(('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:unHide' . ($isPagesTable ? 'Page' : ''))));
551
                    $cells['hide'] = '
552
                        <a class="btn btn-default hiddenHandle ' . $className . '" href="#" onclick="
553
                            ' . htmlspecialchars($onClick) . '"' . 'title="' . $title . '">
554
                            ' . $this->iconFactory->getIcon('actions-edit-unhide', Icon::SIZE_SMALL)->render() . '
555
                        </a>';
556
                } else {
557
                    $title = htmlspecialchars($languageService->sL(('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:hide' . ($isPagesTable ? 'Page' : ''))));
558
                    $cells['hide'] = '
559
                        <a class="btn btn-default hiddenHandle ' . $className . '" href="#" onclick="
560
                            ' . htmlspecialchars($onClick) . '"' . 'title="' . $title . '">
561
                            ' . $this->iconFactory->getIcon('actions-edit-hide', Icon::SIZE_SMALL)->render() . '
562
                        </a>';
563
                }
564
            }
565
            // Drag&Drop Sorting: Sortable handler for script.aculo.us
566
            if ($enabledControls['dragdrop'] && $permsEdit && $enableManualSorting && $inlineConfig['appearance']['useSortable']) {
567
                $cells['dragdrop'] = '
568
                    <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')) . '">
569
                        ' . $this->iconFactory->getIcon('actions-move-move', Icon::SIZE_SMALL)->render() . '
570
                    </span>';
571
            }
572
        } elseif ($data['isInlineDefaultLanguageRecordInLocalizedParentContext'] && $isParentExisting) {
573
            if ($enabledControls['localize'] && $data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
574
                $onClick = 'inline.synchronizeLocalizeRecords(' . GeneralUtility::quoteJSvalue($nameObjectFt) . ', ' . GeneralUtility::quoteJSvalue($rec['uid']) . ');';
575
                $cells['localize'] = '
576
                    <a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:localize')) . '">
577
                        ' . $this->iconFactory->getIcon('actions-document-localize', Icon::SIZE_SMALL)->render() . '
578
                    </a>';
579
            }
580
        }
581
        // If the record is edit-locked by another user, we will show a little warning sign:
582
        if ($lockInfo = BackendUtility::isRecordLocked($foreignTable, $rec['uid'])) {
583
            $cells['locked'] = '
584
				<a class="btn btn-default" href="#" data-toggle="tooltip" data-title="' . htmlspecialchars($lockInfo['msg']) . '">
585
					' . '<span title="' . htmlspecialchars($lockInfo['msg']) . '">' . $this->iconFactory->getIcon('warning-in-use', Icon::SIZE_SMALL)->render() . '</span>' . '
586
				</a>';
587
        }
588
        // Hook: Post-processing of single controls for specific child records:
589
        foreach ($this->hookObjects as $hookObj) {
590
            $hookObj->renderForeignRecordHeaderControl_postProcess($data['inlineParentUid'], $foreignTable, $rec, $inlineConfig, $data['isInlineDefaultLanguageRecordInLocalizedParentContext'], $cells);
591
        }
592
593
        $out = '';
594
        if (!empty($cells['edit']) || !empty($cells['hide']) || !empty($cells['delete'])) {
595
            $out .= '<div class="btn-group btn-group-sm" role="group">' . $cells['edit'] . $cells['hide'] . $cells['delete'] . '</div>';
596
            unset($cells['edit'], $cells['hide'], $cells['delete']);
597
        }
598
        if (!empty($cells['info']) || !empty($cells['new']) || !empty($cells['sort.up']) || !empty($cells['sort.down']) || !empty($cells['dragdrop'])) {
599
            $out .= '<div class="btn-group btn-group-sm" role="group">' . $cells['info'] . $cells['new'] . $cells['sort.up'] . $cells['sort.down'] . $cells['dragdrop'] . '</div>';
600
            unset($cells['info'], $cells['new'], $cells['sort.up'], $cells['sort.down'], $cells['dragdrop']);
601
        }
602
        if (!empty($cells['localize'])) {
603
            $out .= '<div class="btn-group btn-group-sm" role="group">' . $cells['localize'] . '</div>';
604
            unset($cells['localize']);
605
        }
606
        if (!empty($cells)) {
607
            $out .= ' <div class="btn-group btn-group-sm" role="group">' . implode('', $cells) . '</div>';
608
        }
609
        return $out;
610
    }
611
612
    /**
613
     * Normalize a relation "uid" published by transferData, like "1|Company%201"
614
     *
615
     * @param string $string A transferData reference string, containing the uid
616
     * @return string The normalized uid
617
     */
618
    protected function normalizeUid($string)
619
    {
620
        $parts = explode('|', $string);
621
        return $parts[0];
622
    }
623
624
    /**
625
     * Initialized the hook objects for this class.
626
     * Each hook object has to implement the interface
627
     * \TYPO3\CMS\Backend\Form\Element\InlineElementHookInterface
628
     *
629
     * @throws \UnexpectedValueException
630
     */
631
    protected function initHookObjects()
632
    {
633
        $this->hookObjects = [];
634
        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms_inline.php']['tceformsInlineHook'] ?? [] as $className) {
635
            $processObject = GeneralUtility::makeInstance($className);
636
            if (!$processObject instanceof InlineElementHookInterface) {
637
                throw new \UnexpectedValueException($className . ' must implement interface ' . InlineElementHookInterface::class, 1202072000);
638
            }
639
            $this->hookObjects[] = $processObject;
640
        }
641
    }
642
643
    /**
644
     * @return BackendUserAuthentication
645
     */
646
    protected function getBackendUserAuthentication()
647
    {
648
        return $GLOBALS['BE_USER'];
649
    }
650
651
    /**
652
     * @return LanguageService
653
     */
654
    protected function getLanguageService()
655
    {
656
        return $GLOBALS['LANG'];
657
    }
658
}
659