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