[TASK] Remove rendering of label_userFunc due to redundancy
[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\Form\Utility\FormEngineUtility;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
24 use TYPO3\CMS\Core\Database\DatabaseConnection;
25 use TYPO3\CMS\Core\Database\RelationHandler;
26 use TYPO3\CMS\Core\Imaging\Icon;
27 use TYPO3\CMS\Core\Imaging\IconFactory;
28 use TYPO3\CMS\Core\Messaging\FlashMessage;
29 use TYPO3\CMS\Core\Resource\ProcessedFile;
30 use TYPO3\CMS\Core\Resource\ResourceFactory;
31 use TYPO3\CMS\Core\Type\Bitmask\Permission;
32 use TYPO3\CMS\Core\Utility\GeneralUtility;
33 use TYPO3\CMS\Core\Utility\MathUtility;
34 use TYPO3\CMS\Lang\LanguageService;
35
36 /**
37 * Render a single inline record relation.
38 *
39 * This container is called by InlineControlContainer to render single existing records.
40 * Furthermore it is called by FormEngine for an incoming ajax request to expand an existing record
41 * or to create a new one.
42 *
43 * This container creates the outer HTML of single inline records - eg. drag and drop and delete buttons.
44 * For rendering of the record itself processing is handed over to FullRecordContainer.
45 */
46 class InlineRecordContainer extends AbstractContainer
47 {
48 /**
49 * Inline data array used for JSON output
50 *
51 * @var array
52 */
53 protected $inlineData = array();
54
55 /**
56 * @var InlineStackProcessor
57 */
58 protected $inlineStackProcessor;
59
60 /**
61 * Array containing instances of hook classes called once for IRRE objects
62 *
63 * @var array
64 */
65 protected $hookObjects = array();
66
67 /**
68 * @var IconFactory
69 */
70 protected $iconFactory;
71
72 /**
73 * Default constructor
74 *
75 * @param NodeFactory $nodeFactory
76 * @param array $data
77 */
78 public function __construct(NodeFactory $nodeFactory, array $data)
79 {
80 parent::__construct($nodeFactory, $data);
81 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
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 $this->inlineData = $this->data['inlineData'];
93
94 /** @var InlineStackProcessor $inlineStackProcessor */
95 $inlineStackProcessor = GeneralUtility::makeInstance(InlineStackProcessor::class);
96 $this->inlineStackProcessor = $inlineStackProcessor;
97 $inlineStackProcessor->initializeByGivenStructure($this->data['inlineStructure']);
98
99 $this->initHookObjects();
100
101 $parentUid = $this->data['inlineParentUid'];
102 $record = $this->data['databaseRow'];
103 $config = $this->data['inlineParentConfig'];
104
105 $foreign_table = $config['foreign_table'];
106 $foreign_selector = $config['foreign_selector'];
107 $resultArray = $this->initializeResultArray();
108
109 // Send a mapping information to the browser via JSON:
110 // e.g. data[<curTable>][<curId>][<curField>] => data-<pid>-<parentTable>-<parentId>-<parentField>-<curTable>-<curId>-<curField>
111 $formPrefix = $inlineStackProcessor->getCurrentStructureFormPrefix();
112 $domObjectId = $inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid']);
113 $this->inlineData['map'][$formPrefix] = $domObjectId;
114
115 $resultArray['inlineData'] = $this->inlineData;
116
117 // Set this variable if we handle a brand new unsaved record:
118 $isNewRecord = !MathUtility::canBeInterpretedAsInteger($record['uid']);
119 // Set this variable if the only the default language record and inline child has not been localized yet
120 $isDefaultLanguageRecord = $this->data['inlineIsDefaultLanguage'];
121 // If there is a selector field, normalize it:
122 if ($foreign_selector) {
123 $valueToNormalize = $record[$foreign_selector];
124 if (is_array($record[$foreign_selector])) {
125 // @todo: this can be kicked again if always prepared rows are handled here
126 $valueToNormalize = implode(',', $record[$foreign_selector]);
127 }
128 $record[$foreign_selector] = $this->normalizeUid($valueToNormalize);
129 }
130 // Get the current naming scheme for DOM name/id attributes:
131 $appendFormFieldNames = '[' . $foreign_table . '][' . $record['uid'] . ']';
132 $objectId = $domObjectId . '-' . $foreign_table . '-' . $record['uid'];
133 $class = '';
134 $html = '';
135 $combinationHtml = '';
136 if (!$isDefaultLanguageRecord) {
137 // Get configuration:
138 $collapseAll = isset($config['appearance']['collapseAll']) && $config['appearance']['collapseAll'];
139 $expandAll = isset($config['appearance']['collapseAll']) && !$config['appearance']['collapseAll'];
140 $ajaxLoad = !isset($config['appearance']['ajaxLoad']) || $config['appearance']['ajaxLoad'];
141 if ($isNewRecord) {
142 // Show this record expanded or collapsed
143 $isExpanded = $expandAll || (!$collapseAll ? 1 : 0);
144 } else {
145 $isExpanded = $config['renderFieldsOnly'] || !$collapseAll && $this->getExpandedCollapsedState($foreign_table, $record['uid']) || $expandAll;
146 }
147 // Render full content ONLY IF this is an AJAX request, a new record, the record is not collapsed or AJAX loading is explicitly turned off
148 if ($isNewRecord || $isExpanded || !$ajaxLoad) {
149 $combinationHtml = '';
150 if (isset($this->data['combinationChild'])) {
151 $combinationChild = $this->renderCombinationChild($this->data, $appendFormFieldNames);
152 $combinationHtml = $combinationChild['html'];
153 $combinationChild['html'] = '';
154 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $combinationChild);
155 }
156
157 $childArray = $this->renderChild($this->data);
158
159 $html = $childArray['html'];
160 $childArray['html'] = '';
161 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childArray);
162 } else {
163 // This string is the marker for the JS-function to check if the full content has already been loaded
164 $html = '<!--notloaded-->';
165 }
166 if ($isNewRecord) {
167 // Get the top parent table
168 $top = $this->inlineStackProcessor->getStructureLevel(0);
169 $ucFieldName = 'uc[inlineView][' . $top['table'] . '][' . $top['uid'] . ']' . $appendFormFieldNames;
170 // Set additional fields for processing for saving
171 $html .= '<input type="hidden" name="data' . $appendFormFieldNames . '[pid]" value="' . $record['pid'] . '"/>';
172 $html .= '<input type="hidden" name="' . $ucFieldName . '" value="' . $isExpanded . '" />';
173 } else {
174 // Set additional field for processing for saving
175 $html .= '<input type="hidden" name="cmd' . $appendFormFieldNames . '[delete]" value="1" disabled="disabled" />';
176 if (!$isExpanded
177 && !empty($GLOBALS['TCA'][$foreign_table]['ctrl']['enablecolumns']['disabled'])
178 && $ajaxLoad
179 ) {
180 $checked = !empty($record['hidden']) ? ' checked="checked"' : '';
181 $html .= '<input type="checkbox" name="data' . $appendFormFieldNames . '[hidden]_0" value="1"' . $checked . ' />';
182 $html .= '<input type="input" name="data' . $appendFormFieldNames . '[hidden]" value="' . $record['hidden'] . '" />';
183 }
184 }
185 // If this record should be shown collapsed
186 $class = $isExpanded ? 'panel-visible' : 'panel-collapsed';
187 }
188 if ($config['renderFieldsOnly']) {
189 $html = $html . $combinationHtml;
190 } else {
191 // Set the record container with data for output
192 if ($isDefaultLanguageRecord) {
193 $class .= ' t3-form-field-container-inline-placeHolder';
194 }
195 if (isset($record['hidden']) && (int)$record['hidden']) {
196 $class .= ' t3-form-field-container-inline-hidden';
197 }
198 $class .= ($isNewRecord ? ' inlineIsNewRecord' : '');
199 $html = '
200 <div class="panel panel-default panel-condensed ' . trim($class) . '" id="' . $objectId . '_div">
201 <div class="panel-heading" data-toggle="formengine-inline" id="' . $objectId . '_header" data-expandSingle="' . ($config['appearance']['expandSingle'] ? 1 : 0) . '">
202 <div class="form-irre-header">
203 <div class="form-irre-header-cell form-irre-header-icon">
204 <span class="caret"></span>
205 </div>
206 ' . $this->renderForeignRecordHeader($parentUid, $foreign_table, $this->data, $config, $isDefaultLanguageRecord) . '
207 </div>
208 </div>
209 <div class="panel-collapse" id="' . $objectId . '_fields" data-expandSingle="' . ($config['appearance']['expandSingle'] ? 1 : 0) . '" data-returnURL="' . htmlspecialchars(GeneralUtility::getIndpEnv('REQUEST_URI')) . '">' . $html . $combinationHtml . '</div>
210 </div>';
211 }
212
213 $resultArray['html'] = $html;
214 return $resultArray;
215 }
216
217 /**
218 * Render inner child
219 *
220 * @param array $options
221 * @return array Result array
222 */
223 protected function renderChild(array $options)
224 {
225 $domObjectId = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($options['inlineFirstPid']);
226 $options['tabAndInlineStack'][] = [
227 'inline',
228 $domObjectId . '-' . $options['tableName'] . '-' . $options['databaseRow']['uid'],
229 ];
230 // @todo: ugly construct ...
231 $options['inlineData'] = $this->inlineData;
232 $options['renderType'] = 'fullRecordContainer';
233 return $this->nodeFactory->create($options)->render();
234 }
235
236 /**
237 * Render child child
238 *
239 * Render a table with FormEngine, that occurs on an intermediate table but should be editable directly,
240 * so two tables are combined (the intermediate table with attributes and the sub-embedded table).
241 * -> This is a direct embedding over two levels!
242 *
243 * @param array $options
244 * @param string $appendFormFieldNames The [<table>][<uid>] of the parent record (the intermediate table)
245 * @return array Result array
246 */
247 protected function renderCombinationChild(array $options, $appendFormFieldNames)
248 {
249 $childData = $options['combinationChild'];
250 $parentConfig = $options['inlineParentConfig'];
251
252 $resultArray = $this->initializeResultArray();
253
254 // Display Warning FlashMessage if it is not suppressed
255 if (!isset($parentConfig['appearance']['suppressCombinationWarning']) || empty($parentConfig['appearance']['suppressCombinationWarning'])) {
256 $combinationWarningMessage = 'LLL:EXT:lang/locallang_core.xlf:warning.inline_use_combination';
257 if (!empty($parentConfig['appearance']['overwriteCombinationWarningMessage'])) {
258 $combinationWarningMessage = $parentConfig['appearance']['overwriteCombinationWarningMessage'];
259 }
260 $flashMessage = GeneralUtility::makeInstance(
261 FlashMessage::class,
262 $this->getLanguageService()->sL($combinationWarningMessage),
263 '',
264 FlashMessage::WARNING
265 );
266 $resultArray['html'] = $flashMessage->render();
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 /**
288 * Renders the HTML header for a foreign record, such as the title, toggle-function, drag'n'drop, etc.
289 * Later on the command-icons are inserted here.
290 *
291 * @param string $parentUid The uid of the parent (embedding) record (uid or NEW...)
292 * @param string $foreign_table The foreign_table we create a header for
293 * @param array $data Current data
294 * @param array $config content of $PA['fieldConf']['config']
295 * @param bool $isVirtualRecord
296 * @return string The HTML code of the header
297 */
298 protected function renderForeignRecordHeader($parentUid, $foreign_table, $data, $config, $isVirtualRecord = false)
299 {
300 $rec = $data['databaseRow'];
301 // Init:
302 $domObjectId = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid']);
303 $objectId = $domObjectId . '-' . $foreign_table . '-' . $rec['uid'];
304 // We need the returnUrl of the main script when loading the fields via AJAX-call (to correct wizard code, so include it as 3rd parameter)
305 // Pre-Processing:
306 $isOnSymmetricSide = RelationHandler::isOnSymmetricSide($parentUid, $config, $rec);
307 $hasForeignLabel = (bool)(!$isOnSymmetricSide && $config['foreign_label']);
308 $hasSymmetricLabel = (bool)$isOnSymmetricSide && $config['symmetric_label'];
309
310 // Get the record title/label for a record:
311 // Try using a self-defined user function only for formatted labels
312 if (isset($GLOBALS['TCA'][$foreign_table]['ctrl']['formattedLabel_userFunc'])) {
313 $params = array(
314 'table' => $foreign_table,
315 'row' => $rec,
316 'title' => '',
317 'isOnSymmetricSide' => $isOnSymmetricSide,
318 'options' => isset($GLOBALS['TCA'][$foreign_table]['ctrl']['formattedLabel_userFunc_options'])
319 ? $GLOBALS['TCA'][$foreign_table]['ctrl']['formattedLabel_userFunc_options']
320 : array(),
321 'parent' => array(
322 'uid' => $parentUid,
323 'config' => $config
324 )
325 );
326 // callUserFunction requires a third parameter, but we don't want to give $this as reference!
327 $null = null;
328 GeneralUtility::callUserFunction($GLOBALS['TCA'][$foreign_table]['ctrl']['formattedLabel_userFunc'], $params, $null);
329 $recTitle = $params['title'];
330
331 // Try using a normal self-defined user function
332 } elseif (isset($GLOBALS['TCA'][$foreign_table]['ctrl']['label_userFunc'])) {
333 $recTitle = $data['recordTitle'];
334 } elseif ($hasForeignLabel || $hasSymmetricLabel) {
335 $titleCol = $hasForeignLabel ? $config['foreign_label'] : $config['symmetric_label'];
336 // Render title for everything else than group/db:
337 if (isset($this->data['processedTca']['columns'][$titleCol]['config']['type'])
338 && $this->data['processedTca']['columns'][$titleCol]['config']['type'] === 'group'
339 && isset($this->data['processedTca']['columns'][$titleCol]['config']['internal_type'])
340 && $this->data['processedTca']['columns'][$titleCol]['config']['internal_type'] === 'db'
341 ) {
342 $recTitle = BackendUtility::getProcessedValueExtra($foreign_table, $titleCol, $rec[$titleCol], 0, 0, false);
343 } else {
344 // $recTitle could be something like: "tx_table_123|...",
345 $valueParts = GeneralUtility::trimExplode('|', $rec[$titleCol]);
346 $itemParts = GeneralUtility::revExplode('_', $valueParts[0], 2);
347 $recTemp = BackendUtility::getRecordWSOL($itemParts[0], $itemParts[1]);
348 $recTitle = BackendUtility::getRecordTitle($itemParts[0], $recTemp, false);
349 }
350 $recTitle = BackendUtility::getRecordTitlePrep($recTitle);
351 if (trim($recTitle) === '') {
352 $recTitle = BackendUtility::getNoRecordTitle(true);
353 }
354 } else {
355 $recTitle = BackendUtility::getRecordTitle($foreign_table, FormEngineUtility::databaseRowCompatibility($rec), true);
356 }
357
358 $altText = BackendUtility::getRecordIconAltText($rec, $foreign_table);
359
360 $iconImg = '<span title="' . $altText . '" id="' . htmlspecialchars($objectId) . '_icon' . '">' . $this->iconFactory->getIconForRecord($foreign_table, $rec, Icon::SIZE_SMALL)->render() . '</span>';
361 $label = '<span id="' . $objectId . '_label">' . $recTitle . '</span>';
362 $ctrl = $this->renderForeignRecordHeaderControl($parentUid, $foreign_table, $data, $config, $isVirtualRecord);
363 $thumbnail = false;
364
365 // Renders a thumbnail for the header
366 if (!empty($config['appearance']['headerThumbnail']['field'])) {
367 $fieldValue = $rec[$config['appearance']['headerThumbnail']['field']];
368 $firstElement = array_shift(GeneralUtility::trimExplode('|', array_shift(GeneralUtility::trimExplode(',', $fieldValue))));
369 $fileUid = array_pop(BackendUtility::splitTable_Uid($firstElement));
370
371 if (!empty($fileUid)) {
372 $fileObject = ResourceFactory::getInstance()->getFileObject($fileUid);
373 if ($fileObject && $fileObject->isMissing()) {
374 $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($fileObject);
375 $thumbnail = $flashMessage->render();
376 } elseif ($fileObject) {
377 $imageSetup = $config['appearance']['headerThumbnail'];
378 unset($imageSetup['field']);
379 if (!empty($rec['crop'])) {
380 $imageSetup['crop'] = $rec['crop'];
381 }
382 $imageSetup = array_merge(array('width' => '45', 'height' => '45c'), $imageSetup);
383 $processedImage = $fileObject->process(ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, $imageSetup);
384 // Only use a thumbnail if the processing process was successful by checking if image width is set
385 if ($processedImage->getProperty('width')) {
386 $imageUrl = $processedImage->getPublicUrl(true);
387 $thumbnail = '<img src="' . $imageUrl . '" ' .
388 'width="' . $processedImage->getProperty('width') . '" ' .
389 'height="' . $processedImage->getProperty('height') . '" ' .
390 'alt="' . htmlspecialchars($altText) . '" ' .
391 'title="' . htmlspecialchars($altText) . '">';
392 }
393 }
394 }
395 }
396
397 if (!empty($config['appearance']['headerThumbnail']['field']) && $thumbnail) {
398 $mediaContainer = '<div class="form-irre-header-cell form-irre-header-thumbnail" id="' . $objectId . '_thumbnailcontainer">' . $thumbnail . '</div>';
399 } else {
400 $mediaContainer = '<div class="form-irre-header-cell form-irre-header-icon" id="' . $objectId . '_iconcontainer">' . $iconImg . '</div>';
401 }
402 $header = $mediaContainer . '
403 <div class="form-irre-header-cell form-irre-header-body">' . $label . '</div>
404 <div class="form-irre-header-cell form-irre-header-control t3js-formengine-irre-control">' . $ctrl . '</div>';
405
406 return $header;
407 }
408
409 /**
410 * Render the control-icons for a record header (create new, sorting, delete, disable/enable).
411 * Most of the parts are copy&paste from TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList and
412 * modified for the JavaScript calls here
413 *
414 * @param string $parentUid The uid of the parent (embedding) record (uid or NEW...)
415 * @param string $foreign_table The table (foreign_table) we create control-icons for
416 * @param array $data Current data
417 * @param array $config (modified) TCA configuration of the field
418 * @param bool $isVirtualRecord TRUE if the current record is virtual, FALSE otherwise
419 * @return string The HTML code with the control-icons
420 */
421 protected function renderForeignRecordHeaderControl($parentUid, $foreign_table, $data, $config = array(), $isVirtualRecord = false)
422 {
423 $rec = $data['databaseRow'];
424 $languageService = $this->getLanguageService();
425 $backendUser = $this->getBackendUserAuthentication();
426 // Initialize:
427 $cells = array();
428 $additionalCells = array();
429 $isNewItem = substr($rec['uid'], 0, 3) == 'NEW';
430 $isParentExisting = MathUtility::canBeInterpretedAsInteger($parentUid);
431 $tcaTableCtrl = &$GLOBALS['TCA'][$foreign_table]['ctrl'];
432 $tcaTableCols = &$GLOBALS['TCA'][$foreign_table]['columns'];
433 $isPagesTable = $foreign_table === 'pages';
434 $isSysFileReferenceTable = $foreign_table === 'sys_file_reference';
435 $isOnSymmetricSide = RelationHandler::isOnSymmetricSide($parentUid, $config, $rec);
436 $enableManualSorting = $tcaTableCtrl['sortby'] || $config['MM'] || !$isOnSymmetricSide && $config['foreign_sortby'] || $isOnSymmetricSide && $config['symmetric_sortby'];
437 $nameObject = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid']);
438 $nameObjectFt = $nameObject . '-' . $foreign_table;
439 $nameObjectFtId = $nameObjectFt . '-' . $rec['uid'];
440 $calcPerms = $backendUser->calcPerms(BackendUtility::readPageAccess($rec['pid'], $backendUser->getPagePermsClause(1)));
441 // If the listed table is 'pages' we have to request the permission settings for each page:
442 $localCalcPerms = false;
443 if ($isPagesTable) {
444 $localCalcPerms = $backendUser->calcPerms(BackendUtility::getRecord('pages', $rec['uid']));
445 }
446 // This expresses the edit permissions for this particular element:
447 $permsEdit = $isPagesTable && $localCalcPerms & Permission::PAGE_EDIT || !$isPagesTable && $calcPerms & Permission::CONTENT_EDIT;
448 // Controls: Defines which controls should be shown
449 $enabledControls = $config['appearance']['enabledControls'];
450 // Hook: Can disable/enable single controls for specific child records:
451 foreach ($this->hookObjects as $hookObj) {
452 /** @var InlineElementHookInterface $hookObj */
453 $hookObj->renderForeignRecordHeaderControl_preProcess($parentUid, $foreign_table, $rec, $config, $isVirtualRecord, $enabledControls);
454 }
455 if ($data['inlineIsDefaultLanguage']) {
456 $cells['localize.isLocalizable'] = '<span title="' . $languageService->sL('LLL:EXT:lang/locallang_misc.xlf:localize.isLocalizable', true) . '">'
457 . $this->iconFactory->getIcon('actions-edit-localize-status-low', Icon::SIZE_SMALL)->render()
458 . '</span>';
459 }
460 // "Info": (All records)
461 if ($enabledControls['info'] && !$isNewItem) {
462 if ($rec['table_local'] === 'sys_file') {
463 $uid = (int)substr($rec['uid_local'], 9);
464 $table = '_FILE';
465 } else {
466 $uid = $rec['uid'];
467 $table = $foreign_table;
468 }
469 $cells['info'] = '
470 <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) . '">
471 ' . $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL)->render() . '
472 </a>';
473 }
474 // If the table is NOT a read-only table, then show these links:
475 if (!$tcaTableCtrl['readOnly'] && !$isVirtualRecord) {
476 // "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):
477 if ($enabledControls['new'] && ($enableManualSorting || $tcaTableCtrl['useColumnsForDefaultValues'])) {
478 if (!$isPagesTable && $calcPerms & Permission::CONTENT_EDIT || $isPagesTable && $calcPerms & Permission::PAGE_NEW) {
479 $onClick = 'return inline.createNewRecord(' . GeneralUtility::quoteJSvalue($nameObjectFt) . ',' . GeneralUtility::quoteJSvalue($rec['uid']) . ')';
480 $style = '';
481 if ($config['inline']['inlineNewButtonStyle']) {
482 $style = ' style="' . $config['inline']['inlineNewButtonStyle'] . '"';
483 }
484 $cells['new'] = '
485 <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 . '>
486 ' . $this->iconFactory->getIcon('actions-' . ($isPagesTable ? 'page' : 'document') . '-new', Icon::SIZE_SMALL)->render() . '
487 </a>';
488 }
489 }
490 // "Up/Down" links
491 if ($enabledControls['sort'] && $permsEdit && $enableManualSorting) {
492 // Up
493 $onClick = 'return inline.changeSorting(' . GeneralUtility::quoteJSvalue($nameObjectFtId) . ', \'1\')';
494 $style = $config['inline']['first'] == $rec['uid'] ? 'style="visibility: hidden;"' : '';
495 $cells['sort.up'] = '
496 <a class="btn btn-default sortingUp" href="#" onclick="' . htmlspecialchars($onClick) . '" ' . $style . ' title="' . $languageService->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:moveUp', true) . '">
497 ' . $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render() . '
498 </a>';
499 // Down
500 $onClick = 'return inline.changeSorting(' . GeneralUtility::quoteJSvalue($nameObjectFtId) . ', \'-1\')';
501 $style = $config['inline']['last'] == $rec['uid'] ? 'style="visibility: hidden;"' : '';
502 $cells['sort.down'] = '
503 <a class="btn btn-default sortingDown" href="#" onclick="' . htmlspecialchars($onClick) . '" ' . $style . ' title="' . $languageService->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:moveDown', true) . '">
504 ' . $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render() . '
505 </a>';
506 }
507 // "Edit" link:
508 if (($rec['table_local'] === 'sys_file') && !$isNewItem) {
509 $sys_language_uid = 0;
510 if (!empty($rec['sys_language_uid'])) {
511 $sys_language_uid = $rec['sys_language_uid'][0];
512 }
513 $recordInDatabase = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
514 'uid',
515 'sys_file_metadata',
516 'file = ' . (int)substr($rec['uid_local'], 9) . ' AND sys_language_uid = ' . $sys_language_uid
517 );
518 if ($backendUser->check('tables_modify', 'sys_file_metadata')) {
519 $url = BackendUtility::getModuleUrl('record_edit', array(
520 'edit[sys_file_metadata][' . (int)$recordInDatabase['uid'] . ']' => 'edit'
521 ));
522 $editOnClick = 'if (top.content.list_frame) {' .
523 'top.content.list_frame.location.href=' .
524 GeneralUtility::quoteJSvalue($url . '&returnUrl=') .
525 '+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search)' .
526 ';' .
527 '}';
528 $title = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:cm.editMetadata');
529 $cells['editmetadata'] = '
530 <a class="btn btn-default" href="#" class="btn" onclick="' . htmlspecialchars($editOnClick) . '" title="' . htmlspecialchars($title) . '">
531 ' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '
532 </a>';
533 }
534 }
535 // "Delete" link:
536 if ($enabledControls['delete'] && ($isPagesTable && $localCalcPerms & Permission::PAGE_DELETE
537 || !$isPagesTable && $calcPerms & Permission::CONTENT_EDIT
538 || $isSysFileReferenceTable && $calcPerms & Permission::PAGE_EDIT)
539 ) {
540 $title = $languageService->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:delete', true);
541 $icon = $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render();
542 $cells['delete'] = '<a href="#" class="btn btn-default t3js-editform-delete-inline-record" data-objectid="' . htmlspecialchars($nameObjectFtId) . '" title="' . $title . '">' . $icon . '</a>';
543 }
544
545 // "Hide/Unhide" links:
546 $hiddenField = $tcaTableCtrl['enablecolumns']['disabled'];
547 if ($enabledControls['hide'] && $permsEdit && $hiddenField && $tcaTableCols[$hiddenField] && (!$tcaTableCols[$hiddenField]['exclude'] || $backendUser->check('non_exclude_fields', $foreign_table . ':' . $hiddenField))) {
548 $onClick = 'return inline.enableDisableRecord(' . GeneralUtility::quoteJSvalue($nameObjectFtId) . ')';
549 $className = 't3js-' . $nameObjectFtId . '_disabled';
550 if ($rec[$hiddenField]) {
551 $title = $languageService->sL(('LLL:EXT:lang/locallang_mod_web_list.xlf:unHide' . ($isPagesTable ? 'Page' : '')), true);
552 $cells['hide.unhide'] = '
553 <a class="btn btn-default hiddenHandle ' . $className . '" href="#" onclick="'
554 . htmlspecialchars($onClick) . '"' . 'title="' . $title . '">' .
555 $this->iconFactory->getIcon('actions-edit-unhide', Icon::SIZE_SMALL)->render() . '
556 </a>';
557 } else {
558 $title = $languageService->sL(('LLL:EXT:lang/locallang_mod_web_list.xlf:hide' . ($isPagesTable ? 'Page' : '')), true);
559 $cells['hide.hide'] = '
560 <a class="btn btn-default hiddenHandle ' . $className . '" href="#" onclick="'
561 . htmlspecialchars($onClick) . '"' . 'title="' . $title . '">' .
562 $this->iconFactory->getIcon('actions-edit-hide', Icon::SIZE_SMALL)->render() . '
563 </a>';
564 }
565 }
566 // Drag&Drop Sorting: Sortable handler for script.aculo.us
567 if ($enabledControls['dragdrop'] && $permsEdit && $enableManualSorting && $config['appearance']['useSortable']) {
568 $additionalCells['dragdrop'] = '
569 <span class="btn btn-default sortableHandle" data-id="' . htmlspecialchars($rec['uid']) . '" title="' . $languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.move', true) . '">
570 ' . $this->iconFactory->getIcon('actions-move-move', Icon::SIZE_SMALL)->render() . '
571 </span>';
572 }
573 } elseif ($isVirtualRecord && $isParentExisting) {
574 if ($enabledControls['localize'] && $data['inlineIsDefaultLanguage']) {
575 $onClick = 'inline.synchronizeLocalizeRecords(' . GeneralUtility::quoteJSvalue($nameObjectFt) . ', ' . GeneralUtility::quoteJSvalue($rec['uid']) . ');';
576 $cells['localize'] = '
577 <a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $languageService->sL('LLL:EXT:lang/locallang_misc.xlf:localize', true) . '">
578 ' . $this->iconFactory->getIcon('actions-document-localize', Icon::SIZE_SMALL)->render() . '
579 </a>';
580 }
581 }
582 // If the record is edit-locked by another user, we will show a little warning sign:
583 if ($lockInfo = BackendUtility::isRecordLocked($foreign_table, $rec['uid'])) {
584 $cells['locked'] = '
585 <a class="btn btn-default" href="#" onclick="alert(' . GeneralUtility::quoteJSvalue($lockInfo['msg']) . ');return false;">
586 ' . '<span title="' . htmlspecialchars($lockInfo['msg']) . '">' . $this->iconFactory->getIcon('status-warning-in-use', Icon::SIZE_SMALL)->render() . '</span>' . '
587 </a>';
588 }
589 // Hook: Post-processing of single controls for specific child records:
590 foreach ($this->hookObjects as $hookObj) {
591 $hookObj->renderForeignRecordHeaderControl_postProcess($parentUid, $foreign_table, $rec, $config, $isVirtualRecord, $cells);
592 }
593
594 $out = '';
595 if (!empty($cells)) {
596 $out .= ' <div class="btn-group btn-group-sm" role="group">' . implode('', $cells) . '</div>';
597 }
598 if (!empty($additionalCells)) {
599 $out .= ' <div class="btn-group btn-group-sm" role="group">' . implode('', $additionalCells) . '</div>';
600 }
601 return $out;
602 }
603
604 /**
605 * Checks if a uid of a child table is in the inline view settings.
606 *
607 * @param string $table Name of the child table
608 * @param int $uid uid of the the child record
609 * @return bool TRUE=expand, FALSE=collapse
610 */
611 protected function getExpandedCollapsedState($table, $uid)
612 {
613 $inlineView = $this->data['inlineExpandCollapseStateArray'];
614 // @todo Add checking/cleaning for unused tables, records, etc. to save space in uc-field
615 if (isset($inlineView[$table]) && is_array($inlineView[$table])) {
616 if (in_array($uid, $inlineView[$table]) !== false) {
617 return true;
618 }
619 }
620 return false;
621 }
622
623 /**
624 * Normalize a relation "uid" published by transferData, like "1|Company%201"
625 *
626 * @param string $string A transferData reference string, containing the uid
627 * @return string The normalized uid
628 */
629 protected function normalizeUid($string)
630 {
631 $parts = explode('|', $string);
632 return $parts[0];
633 }
634
635 /**
636 * Initialized the hook objects for this class.
637 * Each hook object has to implement the interface
638 * \TYPO3\CMS\Backend\Form\Element\InlineElementHookInterface
639 *
640 * @throws \UnexpectedValueException
641 * @return void
642 */
643 protected function initHookObjects()
644 {
645 $this->hookObjects = array();
646 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms_inline.php']['tceformsInlineHook'])) {
647 $tceformsInlineHook = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms_inline.php']['tceformsInlineHook'];
648 if (is_array($tceformsInlineHook)) {
649 foreach ($tceformsInlineHook as $classData) {
650 $processObject = GeneralUtility::getUserObj($classData);
651 if (!$processObject instanceof InlineElementHookInterface) {
652 throw new \UnexpectedValueException('$processObject must implement interface ' . InlineElementHookInterface::class, 1202072000);
653 }
654 $this->hookObjects[] = $processObject;
655 }
656 }
657 }
658 }
659
660 /**
661 * @return BackendUserAuthentication
662 */
663 protected function getBackendUserAuthentication()
664 {
665 return $GLOBALS['BE_USER'];
666 }
667
668 /**
669 * @return DatabaseConnection
670 */
671 protected function getDatabaseConnection()
672 {
673 return $GLOBALS['TYPO3_DB'];
674 }
675
676 /**
677 * @return LanguageService
678 */
679 protected function getLanguageService()
680 {
681 return $GLOBALS['LANG'];
682 }
683 }