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