2a38ab1c27aad9f4505b82ed7c78b297e963adf5
[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 $hiddenField = $GLOBALS['TCA'][$foreignTable]['ctrl']['enablecolumns']['disabled'];
131 if (!$data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
132 if ($isNewRecord || $data['isInlineChildExpanded']) {
133 // Render full content ONLY IF this is an AJAX request, a new record, or the record is not collapsed
134 $combinationHtml = '';
135 if (isset($data['combinationChild'])) {
136 $combinationChild = $this->renderCombinationChild($data, $appendFormFieldNames);
137 $combinationHtml = $combinationChild['html'];
138 $combinationChild['html'] = '';
139 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $combinationChild);
140 }
141 $childArray = $this->renderChild($data);
142 $html = $childArray['html'];
143 $childArray['html'] = '';
144 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childArray);
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 (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" data-expandSingle="' . ($inlineConfig['appearance']['expandSingle'] ? 1 : 0) . '" data-returnURL="' . htmlspecialchars(GeneralUtility::getIndpEnv('REQUEST_URI')) . '">' . $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/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 $recordTitle = '<em>[' . $languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.no_title', true) . ']</em>';
306 }
307
308 $altText = BackendUtility::getRecordIconAltText($rec, $foreignTable);
309
310 $iconImg = '<span title="' . $altText . '" id="' . htmlspecialchars($objectId) . '_icon' . '">' . $this->iconFactory->getIconForRecord($foreignTable, $rec, Icon::SIZE_SMALL)->render() . '</span>';
311 $label = '<span id="' . $objectId . '_label">' . $recordTitle . '</span>';
312 $ctrl = $this->renderForeignRecordHeaderControl($data);
313 $thumbnail = false;
314
315 // Renders a thumbnail for the header
316 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'] && !empty($inlineConfig['appearance']['headerThumbnail']['field'])) {
317 $fieldValue = $rec[$inlineConfig['appearance']['headerThumbnail']['field']];
318 $firstElement = array_shift(GeneralUtility::trimExplode('|', array_shift(GeneralUtility::trimExplode(',', $fieldValue))));
319 $fileUid = array_pop(BackendUtility::splitTable_Uid($firstElement));
320
321 if (!empty($fileUid)) {
322 try {
323 $fileObject = ResourceFactory::getInstance()->getFileObject($fileUid);
324 } catch (\InvalidArgumentException $e) {
325 $fileObject = null;
326 }
327 if ($fileObject && $fileObject->isMissing()) {
328 $thumbnail .= '<span class="label label-danger">'
329 . htmlspecialchars(static::getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:warning.file_missing'))
330 . '</span>&nbsp;' . htmlspecialchars($fileObject->getName()) . '<br />';
331 } elseif ($fileObject) {
332 $imageSetup = $inlineConfig['appearance']['headerThumbnail'];
333 unset($imageSetup['field']);
334 if (!empty($rec['crop'])) {
335 $imageSetup['crop'] = $rec['crop'];
336 }
337 $imageSetup = array_merge(array('width' => '45', 'height' => '45c'), $imageSetup);
338 $processedImage = $fileObject->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, $imageSetup);
339 // Only use a thumbnail if the processing process was successful by checking if image width is set
340 if ($processedImage->getProperty('width')) {
341 $imageUrl = $processedImage->getPublicUrl(true);
342 $thumbnail = '<img src="' . $imageUrl . '" ' .
343 'width="' . $processedImage->getProperty('width') . '" ' .
344 'height="' . $processedImage->getProperty('height') . '" ' .
345 'alt="' . htmlspecialchars($altText) . '" ' .
346 'title="' . htmlspecialchars($altText) . '">';
347 }
348 }
349 }
350 }
351
352 if (!empty($inlineConfig['appearance']['headerThumbnail']['field']) && $thumbnail) {
353 $mediaContainer = '<div class="form-irre-header-cell form-irre-header-thumbnail" id="' . $objectId . '_thumbnailcontainer">' . $thumbnail . '</div>';
354 } else {
355 $mediaContainer = '<div class="form-irre-header-cell form-irre-header-icon" id="' . $objectId . '_iconcontainer">' . $iconImg . '</div>';
356 }
357 $header = $mediaContainer . '
358 <div class="form-irre-header-cell form-irre-header-body">' . $label . '</div>
359 <div class="form-irre-header-cell form-irre-header-control t3js-formengine-irre-control">' . $ctrl . '</div>';
360
361 return $header;
362 }
363
364 /**
365 * Render the control-icons for a record header (create new, sorting, delete, disable/enable).
366 * Most of the parts are copy&paste from TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList and
367 * modified for the JavaScript calls here
368 *
369 * @param array $data Current data
370 * @return string The HTML code with the control-icons
371 */
372 protected function renderForeignRecordHeaderControl(array $data)
373 {
374 $rec = $data['databaseRow'];
375 $inlineConfig = $data['inlineParentConfig'];
376 $foreignTable = $inlineConfig['foreign_table'];
377 $languageService = $this->getLanguageService();
378 $backendUser = $this->getBackendUserAuthentication();
379 // Initialize:
380 $cells = array();
381 $additionalCells = array();
382 $isNewItem = substr($rec['uid'], 0, 3) == 'NEW';
383 $isParentExisting = MathUtility::canBeInterpretedAsInteger($data['inlineParentUid']);
384 $tcaTableCtrl = $GLOBALS['TCA'][$foreignTable]['ctrl'];
385 $tcaTableCols = $GLOBALS['TCA'][$foreignTable]['columns'];
386 $isPagesTable = $foreignTable === 'pages';
387 $isSysFileReferenceTable = $foreignTable === 'sys_file_reference';
388 $enableManualSorting = $tcaTableCtrl['sortby'] || $inlineConfig['MM'] || !$data['isOnSymmetricSide']
389 && $inlineConfig['foreign_sortby'] || $data['isOnSymmetricSide'] && $inlineConfig['symmetric_sortby'];
390 $nameObject = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($data['inlineFirstPid']);
391 $nameObjectFt = $nameObject . '-' . $foreignTable;
392 $nameObjectFtId = $nameObjectFt . '-' . $rec['uid'];
393 $calcPerms = $backendUser->calcPerms(BackendUtility::readPageAccess($rec['pid'], $backendUser->getPagePermsClause(1)));
394 // If the listed table is 'pages' we have to request the permission settings for each page:
395 $localCalcPerms = false;
396 if ($isPagesTable) {
397 $localCalcPerms = $backendUser->calcPerms(BackendUtility::getRecord('pages', $rec['uid']));
398 }
399 // This expresses the edit permissions for this particular element:
400 $permsEdit = $isPagesTable && $localCalcPerms & Permission::PAGE_EDIT || !$isPagesTable && $calcPerms & Permission::CONTENT_EDIT;
401 // Controls: Defines which controls should be shown
402 $enabledControls = $inlineConfig['appearance']['enabledControls'];
403 // Hook: Can disable/enable single controls for specific child records:
404 foreach ($this->hookObjects as $hookObj) {
405 /** @var InlineElementHookInterface $hookObj */
406 $hookObj->renderForeignRecordHeaderControl_preProcess($data['inlineParentUid'], $foreignTable, $rec, $inlineConfig, $data['isInlineDefaultLanguageRecordInLocalizedParentContext'], $enabledControls);
407 }
408 if ($data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
409 $cells['localize.isLocalizable'] = '<span title="' . $languageService->sL('LLL:EXT:lang/locallang_misc.xlf:localize.isLocalizable', true) . '">'
410 . $this->iconFactory->getIcon('actions-edit-localize-status-low', Icon::SIZE_SMALL)->render()
411 . '</span>';
412 }
413 // "Info": (All records)
414 if ($enabledControls['info'] && !$isNewItem) {
415 if ($rec['table_local'] === 'sys_file') {
416 $uid = (int)substr($rec['uid_local'], 9);
417 $table = '_FILE';
418 } else {
419 $uid = $rec['uid'];
420 $table = $foreignTable;
421 }
422 $cells['info'] = '
423 <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) . '">
424 ' . $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL)->render() . '
425 </a>';
426 }
427 // If the table is NOT a read-only table, then show these links:
428 if (!$tcaTableCtrl['readOnly'] && !$data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
429 // "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):
430 if ($enabledControls['new'] && ($enableManualSorting || $tcaTableCtrl['useColumnsForDefaultValues'])) {
431 if (!$isPagesTable && $calcPerms & Permission::CONTENT_EDIT || $isPagesTable && $calcPerms & Permission::PAGE_NEW) {
432 $onClick = 'return inline.createNewRecord(' . GeneralUtility::quoteJSvalue($nameObjectFt) . ',' . GeneralUtility::quoteJSvalue($rec['uid']) . ')';
433 $style = '';
434 if ($inlineConfig['inline']['inlineNewButtonStyle']) {
435 $style = ' style="' . $inlineConfig['inline']['inlineNewButtonStyle'] . '"';
436 }
437 $cells['new'] = '
438 <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 . '>
439 ' . $this->iconFactory->getIcon('actions-' . ($isPagesTable ? 'page' : 'document') . '-new', Icon::SIZE_SMALL)->render() . '
440 </a>';
441 }
442 }
443 // "Up/Down" links
444 if ($enabledControls['sort'] && $permsEdit && $enableManualSorting) {
445 // Up
446 $onClick = 'return inline.changeSorting(' . GeneralUtility::quoteJSvalue($nameObjectFtId) . ', \'1\')';
447 $style = $inlineConfig['inline']['first'] == $rec['uid'] ? 'style="visibility: hidden;"' : '';
448 $cells['sort.up'] = '
449 <a class="btn btn-default sortingUp" href="#" onclick="' . htmlspecialchars($onClick) . '" ' . $style . ' title="' . $languageService->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:moveUp', true) . '">
450 ' . $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render() . '
451 </a>';
452 // Down
453 $onClick = 'return inline.changeSorting(' . GeneralUtility::quoteJSvalue($nameObjectFtId) . ', \'-1\')';
454 $style = $inlineConfig['inline']['last'] == $rec['uid'] ? 'style="visibility: hidden;"' : '';
455 $cells['sort.down'] = '
456 <a class="btn btn-default sortingDown" href="#" onclick="' . htmlspecialchars($onClick) . '" ' . $style . ' title="' . $languageService->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:moveDown', true) . '">
457 ' . $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render() . '
458 </a>';
459 }
460 // "Edit" link:
461 if (($rec['table_local'] === 'sys_file') && !$isNewItem) {
462 $sys_language_uid = 0;
463 if (!empty($rec['sys_language_uid'])) {
464 $sys_language_uid = $rec['sys_language_uid'][0];
465 }
466 $recordInDatabase = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
467 'uid',
468 'sys_file_metadata',
469 'file = ' . (int)substr($rec['uid_local'], 9) . ' AND sys_language_uid = ' . $sys_language_uid
470 );
471 if ($backendUser->check('tables_modify', 'sys_file_metadata')) {
472 $url = BackendUtility::getModuleUrl('record_edit', array(
473 'edit[sys_file_metadata][' . (int)$recordInDatabase['uid'] . ']' => 'edit'
474 ));
475 $editOnClick = 'if (top.content.list_frame) {' .
476 'top.content.list_frame.location.href=' .
477 GeneralUtility::quoteJSvalue($url . '&returnUrl=') .
478 '+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search)' .
479 ';' .
480 '}';
481 $title = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:cm.editMetadata');
482 $cells['editmetadata'] = '
483 <a class="btn btn-default" href="#" class="btn" onclick="' . htmlspecialchars($editOnClick) . '" title="' . htmlspecialchars($title) . '">
484 ' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '
485 </a>';
486 }
487 }
488 // "Delete" link:
489 if ($enabledControls['delete'] && ($isPagesTable && $localCalcPerms & Permission::PAGE_DELETE
490 || !$isPagesTable && $calcPerms & Permission::CONTENT_EDIT
491 || $isSysFileReferenceTable && $calcPerms & Permission::PAGE_EDIT)
492 ) {
493 $title = $languageService->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:delete', true);
494 $icon = $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render();
495 $cells['delete'] = '<a href="#" class="btn btn-default t3js-editform-delete-inline-record" data-objectid="' . htmlspecialchars($nameObjectFtId) . '" title="' . $title . '">' . $icon . '</a>';
496 }
497
498 // "Hide/Unhide" links:
499 $hiddenField = $tcaTableCtrl['enablecolumns']['disabled'];
500 if ($enabledControls['hide'] && $permsEdit && $hiddenField && $tcaTableCols[$hiddenField] && (!$tcaTableCols[$hiddenField]['exclude'] || $backendUser->check('non_exclude_fields', $foreignTable . ':' . $hiddenField))) {
501 $onClick = 'return inline.enableDisableRecord(' . GeneralUtility::quoteJSvalue($nameObjectFtId) . ',' .
502 GeneralUtility::quoteJSvalue($hiddenField) .')';
503 $className = 't3js-' . $nameObjectFtId . '_disabled';
504 if ($rec[$hiddenField]) {
505 $title = $languageService->sL(('LLL:EXT:lang/locallang_mod_web_list.xlf:unHide' . ($isPagesTable ? 'Page' : '')), true);
506 $cells['hide.unhide'] = '
507 <a class="btn btn-default hiddenHandle ' . $className . '" href="#" onclick="'
508 . htmlspecialchars($onClick) . '"' . 'title="' . $title . '">' .
509 $this->iconFactory->getIcon('actions-edit-unhide', Icon::SIZE_SMALL)->render() . '
510 </a>';
511 } else {
512 $title = $languageService->sL(('LLL:EXT:lang/locallang_mod_web_list.xlf:hide' . ($isPagesTable ? 'Page' : '')), true);
513 $cells['hide.hide'] = '
514 <a class="btn btn-default hiddenHandle ' . $className . '" href="#" onclick="'
515 . htmlspecialchars($onClick) . '"' . 'title="' . $title . '">' .
516 $this->iconFactory->getIcon('actions-edit-hide', Icon::SIZE_SMALL)->render() . '
517 </a>';
518 }
519 }
520 // Drag&Drop Sorting: Sortable handler for script.aculo.us
521 if ($enabledControls['dragdrop'] && $permsEdit && $enableManualSorting && $inlineConfig['appearance']['useSortable']) {
522 $additionalCells['dragdrop'] = '
523 <span class="btn btn-default sortableHandle" data-id="' . htmlspecialchars($rec['uid']) . '" title="' . $languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.move', true) . '">
524 ' . $this->iconFactory->getIcon('actions-move-move', Icon::SIZE_SMALL)->render() . '
525 </span>';
526 }
527 } elseif ($data['isInlineDefaultLanguageRecordInLocalizedParentContext'] && $isParentExisting) {
528 if ($enabledControls['localize'] && $data['isInlineDefaultLanguageRecordInLocalizedParentContext']) {
529 $onClick = 'inline.synchronizeLocalizeRecords(' . GeneralUtility::quoteJSvalue($nameObjectFt) . ', ' . GeneralUtility::quoteJSvalue($rec['uid']) . ');';
530 $cells['localize'] = '
531 <a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $languageService->sL('LLL:EXT:lang/locallang_misc.xlf:localize', true) . '">
532 ' . $this->iconFactory->getIcon('actions-document-localize', Icon::SIZE_SMALL)->render() . '
533 </a>';
534 }
535 }
536 // If the record is edit-locked by another user, we will show a little warning sign:
537 if ($lockInfo = BackendUtility::isRecordLocked($foreignTable, $rec['uid'])) {
538 $cells['locked'] = '
539 <a class="btn btn-default" href="#" onclick="alert(' . GeneralUtility::quoteJSvalue($lockInfo['msg']) . ');return false;">
540 ' . '<span title="' . htmlspecialchars($lockInfo['msg']) . '">' . $this->iconFactory->getIcon('status-warning-in-use', Icon::SIZE_SMALL)->render() . '</span>' . '
541 </a>';
542 }
543 // Hook: Post-processing of single controls for specific child records:
544 foreach ($this->hookObjects as $hookObj) {
545 $hookObj->renderForeignRecordHeaderControl_postProcess($data['inlineParentUid'], $foreignTable, $rec, $inlineConfig, $data['isInlineDefaultLanguageRecordInLocalizedParentContext'], $cells);
546 }
547
548 $out = '';
549 if (!empty($cells)) {
550 $out .= ' <div class="btn-group btn-group-sm" role="group">' . implode('', $cells) . '</div>';
551 }
552 if (!empty($additionalCells)) {
553 $out .= ' <div class="btn-group btn-group-sm" role="group">' . implode('', $additionalCells) . '</div>';
554 }
555 return $out;
556 }
557
558 /**
559 * Normalize a relation "uid" published by transferData, like "1|Company%201"
560 *
561 * @param string $string A transferData reference string, containing the uid
562 * @return string The normalized uid
563 */
564 protected function normalizeUid($string)
565 {
566 $parts = explode('|', $string);
567 return $parts[0];
568 }
569
570 /**
571 * Initialized the hook objects for this class.
572 * Each hook object has to implement the interface
573 * \TYPO3\CMS\Backend\Form\Element\InlineElementHookInterface
574 *
575 * @throws \UnexpectedValueException
576 * @return void
577 */
578 protected function initHookObjects()
579 {
580 $this->hookObjects = array();
581 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms_inline.php']['tceformsInlineHook'])) {
582 $tceformsInlineHook = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms_inline.php']['tceformsInlineHook'];
583 if (is_array($tceformsInlineHook)) {
584 foreach ($tceformsInlineHook as $classData) {
585 $processObject = GeneralUtility::getUserObj($classData);
586 if (!$processObject instanceof InlineElementHookInterface) {
587 throw new \UnexpectedValueException('$processObject must implement interface ' . InlineElementHookInterface::class, 1202072000);
588 }
589 $this->hookObjects[] = $processObject;
590 }
591 }
592 }
593 }
594
595 /**
596 * @return BackendUserAuthentication
597 */
598 protected function getBackendUserAuthentication()
599 {
600 return $GLOBALS['BE_USER'];
601 }
602
603 /**
604 * @return DatabaseConnection
605 */
606 protected function getDatabaseConnection()
607 {
608 return $GLOBALS['TYPO3_DB'];
609 }
610
611 /**
612 * @return LanguageService
613 */
614 protected function getLanguageService()
615 {
616 return $GLOBALS['LANG'];
617 }
618 }