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