[BUGFIX] Use ProcessedFile::CONTEXT_IMAGEPREVIEW for inline preview images
[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\DatabaseConnection;
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 = array();
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 = array();
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 if (!$data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
131 if ($isNewRecord || $data['isInlineChildExpanded']) {
132 // Render full content ONLY IF this is an AJAX request, a new record, or the record is not collapsed
133 $combinationHtml = '';
134 if (isset($data['combinationChild'])) {
135 $combinationChild = $this->renderCombinationChild($data, $appendFormFieldNames);
136 $combinationHtml = $combinationChild['html'];
137 $combinationChild['html'] = '';
138 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $combinationChild);
139 }
140 $childArray = $this->renderChild($data);
141 $html = $childArray['html'];
142 $childArray['html'] = '';
143 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childArray);
144 } else {
145 // This string is the marker for the JS-function to check if the full content has already been loaded
146 $html = '<!--notloaded-->';
147 }
148 if ($isNewRecord) {
149 // Add pid of record as hidden field
150 $html .= '<input type="hidden" name="data' . htmlspecialchars($appendFormFieldNames)
151 . '[pid]" value="' . htmlspecialchars($record['pid']) . '"/>';
152 // Tell DataHandler this record is expanded
153 $ucFieldName = 'uc[inlineView]'
154 . '[' . $data['inlineTopMostParentTableName'] . ']'
155 . '[' . $data['inlineTopMostParentUid'] . ']'
156 . $appendFormFieldNames;
157 $html .= '<input type="hidden" name="' . htmlspecialchars($ucFieldName)
158 . '" value="' . (int)$data['isInlineChildExpanded'] . '" />';
159 } else {
160 // Set additional field for processing for saving
161 $html .= '<input type="hidden" name="cmd' . htmlspecialchars($appendFormFieldNames)
162 . '[delete]" value="1" disabled="disabled" />';
163 if (!$data['isInlineChildExpanded']
164 && !empty($GLOBALS['TCA'][$foreignTable]['ctrl']['enablecolumns']['disabled'])
165 ) {
166 $checked = !empty($record['hidden']) ? ' checked="checked"' : '';
167 $html .= '<input type="checkbox" data-formengine-input-name="data'
168 . htmlspecialchars($appendFormFieldNames)
169 . '[hidden]" value="1"' . $checked . ' />';
170 $html .= '<input type="input" name="data' . htmlspecialchars($appendFormFieldNames)
171 . '[hidden]" value="' . htmlspecialchars($record['hidden']) . '" />';
172 }
173 }
174 // If this record should be shown collapsed
175 $class = $data['isInlineChildExpanded'] ? 'panel-visible' : 'panel-collapsed';
176 }
177 if ($inlineConfig['renderFieldsOnly']) {
178 // Render "body" part only
179 $html = $html . $combinationHtml;
180 } else {
181 // Render header row and content (if expanded)
182 if ($data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
183 $class .= ' t3-form-field-container-inline-placeHolder';
184 }
185 if (isset($record['hidden']) && (int)$record['hidden']) {
186 $class .= ' t3-form-field-container-inline-hidden';
187 }
188 $class .= ($isNewRecord ? ' inlineIsNewRecord' : '');
189 $html = '
190 <div class="panel panel-default panel-condensed ' . trim($class) . '" id="' . htmlspecialchars($objectId) . '_div">
191 <div class="panel-heading" data-toggle="formengine-inline" id="' . htmlspecialchars($objectId) . '_header" data-expandSingle="' . ($inlineConfig['appearance']['expandSingle'] ? 1 : 0) . '">
192 <div class="form-irre-header">
193 <div class="form-irre-header-cell form-irre-header-icon">
194 <span class="caret"></span>
195 </div>
196 ' . $this->renderForeignRecordHeader($data) . '
197 </div>
198 </div>
199 <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>
200 </div>';
201 }
202
203 $resultArray['html'] = $html;
204 return $resultArray;
205 }
206
207 /**
208 * Render inner child
209 *
210 * @param array $data
211 * @return array Result array
212 */
213 protected function renderChild(array $data)
214 {
215 $domObjectId = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($data['inlineFirstPid']);
216 $data['tabAndInlineStack'][] = [
217 'inline',
218 $domObjectId . '-' . $data['tableName'] . '-' . $data['databaseRow']['uid'],
219 ];
220 // @todo: ugly construct ...
221 $data['inlineData'] = $this->inlineData;
222 $data['renderType'] = 'fullRecordContainer';
223 return $this->nodeFactory->create($data)->render();
224 }
225
226 /**
227 * Render child child
228 *
229 * Render a table with FormEngine, that occurs on an intermediate table but should be editable directly,
230 * so two tables are combined (the intermediate table with attributes and the sub-embedded table).
231 * -> This is a direct embedding over two levels!
232 *
233 * @param array $data
234 * @param string $appendFormFieldNames The [<table>][<uid>] of the parent record (the intermediate table)
235 * @return array Result array
236 */
237 protected function renderCombinationChild(array $data, $appendFormFieldNames)
238 {
239 $childData = $data['combinationChild'];
240 $parentConfig = $data['inlineParentConfig'];
241
242 $resultArray = $this->initializeResultArray();
243
244 // Display Warning FlashMessage if it is not suppressed
245 if (!isset($parentConfig['appearance']['suppressCombinationWarning']) || empty($parentConfig['appearance']['suppressCombinationWarning'])) {
246 $combinationWarningMessage = 'LLL:EXT:lang/locallang_core.xlf:warning.inline_use_combination';
247 if (!empty($parentConfig['appearance']['overwriteCombinationWarningMessage'])) {
248 $combinationWarningMessage = $parentConfig['appearance']['overwriteCombinationWarningMessage'];
249 }
250 $flashMessage = GeneralUtility::makeInstance(
251 FlashMessage::class,
252 $this->getLanguageService()->sL($combinationWarningMessage),
253 '',
254 FlashMessage::WARNING
255 );
256 $resultArray['html'] = $flashMessage->render();
257 }
258
259 $childArray = $this->renderChild($childData);
260 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childArray);
261
262 // If this is a new record, add a pid value to store this record and the pointer value for the intermediate table
263 if ($childData['command'] === 'new') {
264 $comboFormFieldName = 'data[' . $childData['tableName'] . '][' . $childData['databaseRow']['uid'] . '][pid]';
265 $resultArray['html'] .= '<input type="hidden" name="' . htmlspecialchars($comboFormFieldName) . '" value="' . htmlspecialchars($childData['databaseRow']['pid']) . '" />';
266 }
267 // If the foreign_selector field is also responsible for uniqueness, tell the browser the uid of the "other" side of the relation
268 if ($childData['command'] === 'new' || $parentConfig['foreign_unique'] === $parentConfig['foreign_selector']) {
269 $parentFormFieldName = 'data' . $appendFormFieldNames . '[' . $parentConfig['foreign_selector'] . ']';
270 $resultArray['html'] .= '<input type="hidden" name="' . htmlspecialchars($parentFormFieldName) . '" value="' . htmlspecialchars($childData['databaseRow']['uid']) . '" />';
271 }
272
273 return $resultArray;
274 }
275
276 /**
277 * Renders the HTML header for a foreign record, such as the title, toggle-function, drag'n'drop, etc.
278 * Later on the command-icons are inserted here.
279 *
280 * @param array $data Current data
281 * @return string The HTML code of the header
282 */
283 protected function renderForeignRecordHeader(array $data)
284 {
285 $languageService = $this->getLanguageService();
286 $inlineConfig = $data['inlineParentConfig'];
287 $foreignTable = $inlineConfig['foreign_table'];
288 $rec = $data['databaseRow'];
289 // Init:
290 $domObjectId = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($data['inlineFirstPid']);
291 $objectId = $domObjectId . '-' . $foreignTable . '-' . $rec['uid'];
292
293 $recordTitle = $data['recordTitle'];
294 if (empty($recordTitle)) {
295 $recordTitle = '<em>[' . $languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.no_title', true) . ']</em>';
296 }
297
298 $altText = BackendUtility::getRecordIconAltText($rec, $foreignTable);
299
300 $iconImg = '<span title="' . $altText . '" id="' . htmlspecialchars($objectId) . '_icon' . '">' . $this->iconFactory->getIconForRecord($foreignTable, $rec, Icon::SIZE_SMALL)->render() . '</span>';
301 $label = '<span id="' . $objectId . '_label">' . $recordTitle . '</span>';
302 $ctrl = $this->renderForeignRecordHeaderControl($data);
303 $thumbnail = false;
304
305 // Renders a thumbnail for the header
306 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'] && !empty($inlineConfig['appearance']['headerThumbnail']['field'])) {
307 $fieldValue = $rec[$inlineConfig['appearance']['headerThumbnail']['field']];
308 $firstElement = array_shift(GeneralUtility::trimExplode('|', array_shift(GeneralUtility::trimExplode(',', $fieldValue))));
309 $fileUid = array_pop(BackendUtility::splitTable_Uid($firstElement));
310
311 if (!empty($fileUid)) {
312 try {
313 $fileObject = ResourceFactory::getInstance()->getFileObject($fileUid);
314 } catch (\InvalidArgumentException $e) {
315 $fileObject = null;
316 }
317 if ($fileObject && $fileObject->isMissing()) {
318 $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($fileObject);
319 $thumbnail = $flashMessage->render();
320 } elseif ($fileObject) {
321 $imageSetup = $inlineConfig['appearance']['headerThumbnail'];
322 unset($imageSetup['field']);
323 if (!empty($rec['crop'])) {
324 $imageSetup['crop'] = $rec['crop'];
325 }
326 $imageSetup = array_merge(array('width' => '45', 'height' => '45c'), $imageSetup);
327 $processedImage = $fileObject->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, $imageSetup);
328 // Only use a thumbnail if the processing process was successful by checking if image width is set
329 if ($processedImage->getProperty('width')) {
330 $imageUrl = $processedImage->getPublicUrl(true);
331 $thumbnail = '<img src="' . $imageUrl . '" ' .
332 'width="' . $processedImage->getProperty('width') . '" ' .
333 'height="' . $processedImage->getProperty('height') . '" ' .
334 'alt="' . htmlspecialchars($altText) . '" ' .
335 'title="' . htmlspecialchars($altText) . '">';
336 }
337 }
338 }
339 }
340
341 if (!empty($inlineConfig['appearance']['headerThumbnail']['field']) && $thumbnail) {
342 $mediaContainer = '<div class="form-irre-header-cell form-irre-header-thumbnail" id="' . $objectId . '_thumbnailcontainer">' . $thumbnail . '</div>';
343 } else {
344 $mediaContainer = '<div class="form-irre-header-cell form-irre-header-icon" id="' . $objectId . '_iconcontainer">' . $iconImg . '</div>';
345 }
346 $header = $mediaContainer . '
347 <div class="form-irre-header-cell form-irre-header-body">' . $label . '</div>
348 <div class="form-irre-header-cell form-irre-header-control t3js-formengine-irre-control">' . $ctrl . '</div>';
349
350 return $header;
351 }
352
353 /**
354 * Render the control-icons for a record header (create new, sorting, delete, disable/enable).
355 * Most of the parts are copy&paste from TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList and
356 * modified for the JavaScript calls here
357 *
358 * @param array $data Current data
359 * @return string The HTML code with the control-icons
360 */
361 protected function renderForeignRecordHeaderControl(array $data)
362 {
363 $rec = $data['databaseRow'];
364 $inlineConfig = $data['inlineParentConfig'];
365 $foreignTable = $inlineConfig['foreign_table'];
366 $languageService = $this->getLanguageService();
367 $backendUser = $this->getBackendUserAuthentication();
368 // Initialize:
369 $cells = array();
370 $additionalCells = array();
371 $isNewItem = substr($rec['uid'], 0, 3) == 'NEW';
372 $isParentExisting = MathUtility::canBeInterpretedAsInteger($data['inlineParentUid']);
373 $tcaTableCtrl = &$GLOBALS['TCA'][$foreignTable]['ctrl'];
374 $tcaTableCols = &$GLOBALS['TCA'][$foreignTable]['columns'];
375 $isPagesTable = $foreignTable === 'pages';
376 $isSysFileReferenceTable = $foreignTable === 'sys_file_reference';
377 $enableManualSorting = $tcaTableCtrl['sortby'] || $inlineConfig['MM'] || !$data['isOnSymmetricSide']
378 && $inlineConfig['foreign_sortby'] || $data['isOnSymmetricSide'] && $inlineConfig['symmetric_sortby'];
379 $nameObject = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($data['inlineFirstPid']);
380 $nameObjectFt = $nameObject . '-' . $foreignTable;
381 $nameObjectFtId = $nameObjectFt . '-' . $rec['uid'];
382 $calcPerms = $backendUser->calcPerms(BackendUtility::readPageAccess($rec['pid'], $backendUser->getPagePermsClause(1)));
383 // If the listed table is 'pages' we have to request the permission settings for each page:
384 $localCalcPerms = false;
385 if ($isPagesTable) {
386 $localCalcPerms = $backendUser->calcPerms(BackendUtility::getRecord('pages', $rec['uid']));
387 }
388 // This expresses the edit permissions for this particular element:
389 $permsEdit = $isPagesTable && $localCalcPerms & Permission::PAGE_EDIT || !$isPagesTable && $calcPerms & Permission::CONTENT_EDIT;
390 // Controls: Defines which controls should be shown
391 $enabledControls = $inlineConfig['appearance']['enabledControls'];
392 // Hook: Can disable/enable single controls for specific child records:
393 foreach ($this->hookObjects as $hookObj) {
394 /** @var InlineElementHookInterface $hookObj */
395 $hookObj->renderForeignRecordHeaderControl_preProcess($data['inlineParentUid'], $foreignTable, $rec, $inlineConfig, $data['isInlineDefaultLanguageRecordInLocalizedParentContext'], $enabledControls);
396 }
397 if ($data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
398 $cells['localize.isLocalizable'] = '<span title="' . $languageService->sL('LLL:EXT:lang/locallang_misc.xlf:localize.isLocalizable', true) . '">'
399 . $this->iconFactory->getIcon('actions-edit-localize-status-low', Icon::SIZE_SMALL)->render()
400 . '</span>';
401 }
402 // "Info": (All records)
403 if ($enabledControls['info'] && !$isNewItem) {
404 if ($rec['table_local'] === 'sys_file') {
405 $uid = (int)substr($rec['uid_local'], 9);
406 $table = '_FILE';
407 } else {
408 $uid = $rec['uid'];
409 $table = $foreignTable;
410 }
411 $cells['info'] = '
412 <a class="btn btn-default" href="#" onclick="' . htmlspecialchars(('top.launchView(' . GeneralUtility::quoteJSvalue($table) . ', ' . GeneralUtility::quoteJSvalue($uid) . '); return false;')) . '" title="' . $languageService->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:showInfo', true) . '">
413 ' . $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL)->render() . '
414 </a>';
415 }
416 // If the table is NOT a read-only table, then show these links:
417 if (!$tcaTableCtrl['readOnly'] && !$data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
418 // "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):
419 if ($enabledControls['new'] && ($enableManualSorting || $tcaTableCtrl['useColumnsForDefaultValues'])) {
420 if (!$isPagesTable && $calcPerms & Permission::CONTENT_EDIT || $isPagesTable && $calcPerms & Permission::PAGE_NEW) {
421 $onClick = 'return inline.createNewRecord(' . GeneralUtility::quoteJSvalue($nameObjectFt) . ',' . GeneralUtility::quoteJSvalue($rec['uid']) . ')';
422 $style = '';
423 if ($inlineConfig['inline']['inlineNewButtonStyle']) {
424 $style = ' style="' . $inlineConfig['inline']['inlineNewButtonStyle'] . '"';
425 }
426 $cells['new'] = '
427 <a class="btn btn-default inlineNewButton ' . $this->inlineData['config'][$nameObject]['md5'] . '" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $languageService->sL(('LLL:EXT:lang/locallang_mod_web_list.xlf:new' . ($isPagesTable ? 'Page' : 'Record')), true) . '" ' . $style . '>
428 ' . $this->iconFactory->getIcon('actions-' . ($isPagesTable ? 'page' : 'document') . '-new', Icon::SIZE_SMALL)->render() . '
429 </a>';
430 }
431 }
432 // "Up/Down" links
433 if ($enabledControls['sort'] && $permsEdit && $enableManualSorting) {
434 // Up
435 $onClick = 'return inline.changeSorting(' . GeneralUtility::quoteJSvalue($nameObjectFtId) . ', \'1\')';
436 $style = $inlineConfig['inline']['first'] == $rec['uid'] ? 'style="visibility: hidden;"' : '';
437 $cells['sort.up'] = '
438 <a class="btn btn-default sortingUp" href="#" onclick="' . htmlspecialchars($onClick) . '" ' . $style . ' title="' . $languageService->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:moveUp', true) . '">
439 ' . $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render() . '
440 </a>';
441 // Down
442 $onClick = 'return inline.changeSorting(' . GeneralUtility::quoteJSvalue($nameObjectFtId) . ', \'-1\')';
443 $style = $inlineConfig['inline']['last'] == $rec['uid'] ? 'style="visibility: hidden;"' : '';
444 $cells['sort.down'] = '
445 <a class="btn btn-default sortingDown" href="#" onclick="' . htmlspecialchars($onClick) . '" ' . $style . ' title="' . $languageService->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:moveDown', true) . '">
446 ' . $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render() . '
447 </a>';
448 }
449 // "Edit" link:
450 if (($rec['table_local'] === 'sys_file') && !$isNewItem) {
451 $sys_language_uid = 0;
452 if (!empty($rec['sys_language_uid'])) {
453 $sys_language_uid = $rec['sys_language_uid'][0];
454 }
455 $recordInDatabase = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
456 'uid',
457 'sys_file_metadata',
458 'file = ' . (int)substr($rec['uid_local'], 9) . ' AND sys_language_uid = ' . $sys_language_uid
459 );
460 if ($backendUser->check('tables_modify', 'sys_file_metadata')) {
461 $url = BackendUtility::getModuleUrl('record_edit', array(
462 'edit[sys_file_metadata][' . (int)$recordInDatabase['uid'] . ']' => 'edit'
463 ));
464 $editOnClick = 'if (top.content.list_frame) {' .
465 'top.content.list_frame.location.href=' .
466 GeneralUtility::quoteJSvalue($url . '&returnUrl=') .
467 '+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search)' .
468 ';' .
469 '}';
470 $title = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:cm.editMetadata');
471 $cells['editmetadata'] = '
472 <a class="btn btn-default" href="#" class="btn" onclick="' . htmlspecialchars($editOnClick) . '" title="' . htmlspecialchars($title) . '">
473 ' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '
474 </a>';
475 }
476 }
477 // "Delete" link:
478 if ($enabledControls['delete'] && ($isPagesTable && $localCalcPerms & Permission::PAGE_DELETE
479 || !$isPagesTable && $calcPerms & Permission::CONTENT_EDIT
480 || $isSysFileReferenceTable && $calcPerms & Permission::PAGE_EDIT)
481 ) {
482 $title = $languageService->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:delete', true);
483 $icon = $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render();
484 $cells['delete'] = '<a href="#" class="btn btn-default t3js-editform-delete-inline-record" data-objectid="' . htmlspecialchars($nameObjectFtId) . '" title="' . $title . '">' . $icon . '</a>';
485 }
486
487 // "Hide/Unhide" links:
488 $hiddenField = $tcaTableCtrl['enablecolumns']['disabled'];
489 if ($enabledControls['hide'] && $permsEdit && $hiddenField && $tcaTableCols[$hiddenField] && (!$tcaTableCols[$hiddenField]['exclude'] || $backendUser->check('non_exclude_fields', $foreignTable . ':' . $hiddenField))) {
490 $onClick = 'return inline.enableDisableRecord(' . GeneralUtility::quoteJSvalue($nameObjectFtId) . ')';
491 $className = 't3js-' . $nameObjectFtId . '_disabled';
492 if ($rec[$hiddenField]) {
493 $title = $languageService->sL(('LLL:EXT:lang/locallang_mod_web_list.xlf:unHide' . ($isPagesTable ? 'Page' : '')), true);
494 $cells['hide.unhide'] = '
495 <a class="btn btn-default hiddenHandle ' . $className . '" href="#" onclick="'
496 . htmlspecialchars($onClick) . '"' . 'title="' . $title . '">' .
497 $this->iconFactory->getIcon('actions-edit-unhide', Icon::SIZE_SMALL)->render() . '
498 </a>';
499 } else {
500 $title = $languageService->sL(('LLL:EXT:lang/locallang_mod_web_list.xlf:hide' . ($isPagesTable ? 'Page' : '')), true);
501 $cells['hide.hide'] = '
502 <a class="btn btn-default hiddenHandle ' . $className . '" href="#" onclick="'
503 . htmlspecialchars($onClick) . '"' . 'title="' . $title . '">' .
504 $this->iconFactory->getIcon('actions-edit-hide', Icon::SIZE_SMALL)->render() . '
505 </a>';
506 }
507 }
508 // Drag&Drop Sorting: Sortable handler for script.aculo.us
509 if ($enabledControls['dragdrop'] && $permsEdit && $enableManualSorting && $inlineConfig['appearance']['useSortable']) {
510 $additionalCells['dragdrop'] = '
511 <span class="btn btn-default sortableHandle" data-id="' . htmlspecialchars($rec['uid']) . '" title="' . $languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.move', true) . '">
512 ' . $this->iconFactory->getIcon('actions-move-move', Icon::SIZE_SMALL)->render() . '
513 </span>';
514 }
515 } elseif ($data['isInlineDefaultLanguageRecordInLocalizedParentContext'] && $isParentExisting) {
516 if ($enabledControls['localize'] && $data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
517 $onClick = 'inline.synchronizeLocalizeRecords(' . GeneralUtility::quoteJSvalue($nameObjectFt) . ', ' . GeneralUtility::quoteJSvalue($rec['uid']) . ');';
518 $cells['localize'] = '
519 <a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $languageService->sL('LLL:EXT:lang/locallang_misc.xlf:localize', true) . '">
520 ' . $this->iconFactory->getIcon('actions-document-localize', Icon::SIZE_SMALL)->render() . '
521 </a>';
522 }
523 }
524 // If the record is edit-locked by another user, we will show a little warning sign:
525 if ($lockInfo = BackendUtility::isRecordLocked($foreignTable, $rec['uid'])) {
526 $cells['locked'] = '
527 <a class="btn btn-default" href="#" onclick="alert(' . GeneralUtility::quoteJSvalue($lockInfo['msg']) . ');return false;">
528 ' . '<span title="' . htmlspecialchars($lockInfo['msg']) . '">' . $this->iconFactory->getIcon('status-warning-in-use', Icon::SIZE_SMALL)->render() . '</span>' . '
529 </a>';
530 }
531 // Hook: Post-processing of single controls for specific child records:
532 foreach ($this->hookObjects as $hookObj) {
533 $hookObj->renderForeignRecordHeaderControl_postProcess($data['inlineParentUid'], $foreignTable, $rec, $inlineConfig, $data['isInlineDefaultLanguageRecordInLocalizedParentContext'], $cells);
534 }
535
536 $out = '';
537 if (!empty($cells)) {
538 $out .= ' <div class="btn-group btn-group-sm" role="group">' . implode('', $cells) . '</div>';
539 }
540 if (!empty($additionalCells)) {
541 $out .= ' <div class="btn-group btn-group-sm" role="group">' . implode('', $additionalCells) . '</div>';
542 }
543 return $out;
544 }
545
546 /**
547 * Normalize a relation "uid" published by transferData, like "1|Company%201"
548 *
549 * @param string $string A transferData reference string, containing the uid
550 * @return string The normalized uid
551 */
552 protected function normalizeUid($string)
553 {
554 $parts = explode('|', $string);
555 return $parts[0];
556 }
557
558 /**
559 * Initialized the hook objects for this class.
560 * Each hook object has to implement the interface
561 * \TYPO3\CMS\Backend\Form\Element\InlineElementHookInterface
562 *
563 * @throws \UnexpectedValueException
564 * @return void
565 */
566 protected function initHookObjects()
567 {
568 $this->hookObjects = array();
569 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms_inline.php']['tceformsInlineHook'])) {
570 $tceformsInlineHook = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms_inline.php']['tceformsInlineHook'];
571 if (is_array($tceformsInlineHook)) {
572 foreach ($tceformsInlineHook as $classData) {
573 $processObject = GeneralUtility::getUserObj($classData);
574 if (!$processObject instanceof InlineElementHookInterface) {
575 throw new \UnexpectedValueException('$processObject must implement interface ' . InlineElementHookInterface::class, 1202072000);
576 }
577 $this->hookObjects[] = $processObject;
578 }
579 }
580 }
581 }
582
583 /**
584 * @return BackendUserAuthentication
585 */
586 protected function getBackendUserAuthentication()
587 {
588 return $GLOBALS['BE_USER'];
589 }
590
591 /**
592 * @return DatabaseConnection
593 */
594 protected function getDatabaseConnection()
595 {
596 return $GLOBALS['TYPO3_DB'];
597 }
598
599 /**
600 * @return LanguageService
601 */
602 protected function getLanguageService()
603 {
604 return $GLOBALS['LANG'];
605 }
606 }