[BUGFIX] Editing title inline now updates correct language
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / View / PageLayoutView.php
1 <?php
2 namespace TYPO3\CMS\Backend\View;
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\Controller\Page\LocalizationController;
18 use TYPO3\CMS\Backend\Controller\PageLayoutController;
19 use TYPO3\CMS\Backend\Utility\BackendUtility;
20 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
21 use TYPO3\CMS\Core\Database\ConnectionPool;
22 use TYPO3\CMS\Core\Database\DatabaseConnection;
23 use TYPO3\CMS\Core\Database\Query\QueryHelper;
24 use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
25 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
26 use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
27 use TYPO3\CMS\Core\Imaging\Icon;
28 use TYPO3\CMS\Core\Imaging\IconFactory;
29 use TYPO3\CMS\Core\Messaging\FlashMessage;
30 use TYPO3\CMS\Core\Messaging\FlashMessageService;
31 use TYPO3\CMS\Core\Page\PageRenderer;
32 use TYPO3\CMS\Core\Type\Bitmask\Permission;
33 use TYPO3\CMS\Core\Utility\GeneralUtility;
34 use TYPO3\CMS\Core\Utility\StringUtility;
35 use TYPO3\CMS\Core\Versioning\VersionState;
36 use TYPO3\CMS\Extbase\Service\FlexFormService;
37 use TYPO3\CMS\Fluid\View\StandaloneView;
38
39 /**
40 * Child class for the Web > Page module
41 */
42 class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList
43 {
44 /**
45 * If TRUE, users/groups are shown in the page info box.
46 *
47 * @var int
48 */
49 public $pI_showUser = 0;
50
51 /**
52 * The number of successive records to edit when showing content elements.
53 *
54 * @var int
55 */
56 public $nextThree = 3;
57
58 /**
59 * If TRUE, disables the edit-column icon for tt_content elements
60 *
61 * @var int
62 */
63 public $pages_noEditColumns = 0;
64
65 /**
66 * If TRUE, new-wizards are linked to rather than the regular new-element list.
67 *
68 * @var int
69 */
70 public $option_newWizard = 1;
71
72 /**
73 * If set to "1", will link a big button to content element wizard.
74 *
75 * @var int
76 */
77 public $ext_function = 0;
78
79 /**
80 * If TRUE, elements will have edit icons (probably this is whether the user has permission to edit the page content). Set externally.
81 *
82 * @var int
83 */
84 public $doEdit = 1;
85
86 /**
87 * Age prefixes for displaying times. May be set externally to localized values.
88 *
89 * @var string
90 */
91 public $agePrefixes = ' min| hrs| days| yrs| min| hour| day| year';
92
93 /**
94 * Array of tables to be listed by the Web > Page module in addition to the default tables.
95 *
96 * @var array
97 */
98 public $externalTables = [];
99
100 /**
101 * "Pseudo" Description -table name
102 *
103 * @var string
104 */
105 public $descrTable;
106
107 /**
108 * If set TRUE, the language mode of tt_content elements will be rendered with hard binding between
109 * default language content elements and their translations!
110 *
111 * @var bool
112 */
113 public $defLangBinding = false;
114
115 /**
116 * External, static: Configuration of tt_content element display:
117 *
118 * @var array
119 */
120 public $tt_contentConfig = [
121 // Boolean: Display info-marks or not
122 'showInfo' => 1,
123 // Boolean: Display up/down arrows and edit icons for tt_content records
124 'showCommands' => 1,
125 'languageCols' => 0,
126 'languageMode' => 0,
127 'languageColsPointer' => 0,
128 'showHidden' => 1,
129 // Displays hidden records as well
130 'sys_language_uid' => 0,
131 // Which language
132 'cols' => '1,0,2,3',
133 'activeCols' => '1,0,2,3'
134 // Which columns can be accessed by current BE user
135 ];
136
137 /**
138 * Contains icon/title of pages which are listed in the tables menu (see getTableMenu() function )
139 *
140 * @var array
141 */
142 public $activeTables = [];
143
144 /**
145 * @var array
146 */
147 public $tt_contentData = [
148 'nextThree' => [],
149 'prev' => [],
150 'next' => []
151 ];
152
153 /**
154 * Used to store labels for CTypes for tt_content elements
155 *
156 * @var array
157 */
158 public $CType_labels = [];
159
160 /**
161 * Used to store labels for the various fields in tt_content elements
162 *
163 * @var array
164 */
165 public $itemLabels = [];
166
167 /**
168 * @var \TYPO3\CMS\Backend\Clipboard\Clipboard
169 */
170 protected $clipboard;
171
172 /**
173 * @var array
174 */
175 protected $plusPages = [];
176
177 /**
178 * User permissions
179 *
180 * @var int
181 */
182 public $ext_CALC_PERMS;
183
184 /**
185 * Current ids page record
186 *
187 * @var array
188 */
189 protected $pageinfo;
190
191 /**
192 * Caches the available languages in a colPos
193 *
194 * @var array
195 */
196 protected $languagesInColumnCache = [];
197
198 /**
199 * Caches the amount of content elements as a matrix
200 *
201 * @var array
202 * @internal
203 */
204 protected $contentElementCache = [];
205
206 /**
207 * @var IconFactory
208 */
209 protected $iconFactory;
210
211 /**
212 * Stores whether a certain language has translations in it
213 *
214 * @var array
215 */
216 protected $languageHasTranslationsCache = [];
217
218 /**
219 * @var LocalizationController
220 */
221 protected $localizationController;
222
223 /**
224 * Construct to initialize class variables.
225 */
226 public function __construct()
227 {
228 parent::__construct();
229 $this->localizationController = GeneralUtility::makeInstance(LocalizationController::class);
230 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
231 $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
232 $pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
233 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
234 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Localization');
235 }
236
237 /*****************************************
238 *
239 * Renderings
240 *
241 *****************************************/
242 /**
243 * Adds the code of a single table
244 *
245 * @param string $table Table name
246 * @param int $id Current page id
247 * @param string $fields
248 * @return string HTML for listing.
249 */
250 public function getTable($table, $id, $fields = '')
251 {
252 if (isset($this->externalTables[$table])) {
253 return $this->getExternalTables($id, $table);
254 } else {
255 // Branch out based on table name:
256 switch ($table) {
257 case 'pages':
258 return $this->getTable_pages($id);
259 break;
260 case 'tt_content':
261 return $this->getTable_tt_content($id);
262 break;
263 default:
264 return '';
265 }
266 }
267 }
268
269 /**
270 * Renders an external table from page id
271 *
272 * @param int $id Page id
273 * @param string $table Name of the table
274 * @return string HTML for the listing
275 */
276 public function getExternalTables($id, $table)
277 {
278 $type = $this->getPageLayoutController()->MOD_SETTINGS[$table];
279 if (!isset($type)) {
280 $type = 0;
281 }
282 // eg. "name;title;email;company,image"
283 $fList = $this->externalTables[$table][$type]['fList'];
284 // The columns are separeted by comma ','.
285 // Values separated by semicolon ';' are shown in the same column.
286 $icon = $this->externalTables[$table][$type]['icon'];
287 $addWhere = $this->externalTables[$table][$type]['addWhere'];
288 // Create listing
289 $out = $this->makeOrdinaryList($table, $id, $fList, $icon, $addWhere);
290 return $out;
291 }
292
293 /**
294 * Renders records from the pages table from page id
295 * (Used to get information about the page tree content by "Web>Info"!)
296 *
297 * @param int $id Page id
298 * @return string HTML for the listing
299 */
300 public function getTable_pages($id)
301 {
302 // Initializing:
303 $out = '';
304 $lang = $this->getLanguageService();
305 // Select current page:
306 if (!$id) {
307 // The root has a pseudo record in pageinfo...
308 $row = $this->getPageLayoutController()->pageinfo;
309 } else {
310 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
311 ->getQueryBuilderForTable('pages');
312 $queryBuilder->getRestrictions()
313 ->removeAll()
314 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
315 $row = $queryBuilder
316 ->select('*')
317 ->from('pages')
318 ->where(
319 $queryBuilder->expr()->eq('uid', (int)$id),
320 $this->getBackendUser()->getPagePermsClause(1)
321 )
322 ->execute()
323 ->fetch();
324 BackendUtility::workspaceOL('pages', $row);
325 }
326 // If there was found a page:
327 if (is_array($row)) {
328 // Select which fields to show:
329 $pKey = $this->getPageLayoutController()->MOD_SETTINGS['pages'];
330 switch ($pKey) {
331 case 1:
332 $this->fieldArray = ['title', 'uid'] + array_keys($this->cleanTableNames());
333 break;
334 case 2:
335 $this->fieldArray = [
336 'title',
337 'uid',
338 'lastUpdated',
339 'newUntil',
340 'no_cache',
341 'cache_timeout',
342 'php_tree_stop',
343 'TSconfig',
344 'is_siteroot',
345 'fe_login_mode'
346 ];
347 break;
348 default:
349 $this->fieldArray = [
350 'title',
351 'uid',
352 'alias',
353 'starttime',
354 'endtime',
355 'fe_group',
356 'target',
357 'url',
358 'shortcut',
359 'shortcut_mode'
360 ];
361 }
362 // Getting select-depth:
363 $depth = (int)$this->getPageLayoutController()->MOD_SETTINGS['pages_levels'];
364 // Overriding a few things:
365 $this->no_noWrap = 0;
366 // Items
367 $this->eCounter = $this->firstElementNumber;
368 // Creating elements:
369 list($flag, $code) = $this->fwd_rwd_nav();
370 $out .= $code;
371 $editUids = [];
372 if ($flag) {
373 // Getting children:
374 $theRows = $this->getPageRecordsRecursive($row['uid'], $depth);
375 if ($this->getBackendUser()->doesUserHaveAccess($row, 2) && $row['uid'] > 0) {
376 $editUids[] = $row['uid'];
377 }
378 $out .= $this->pages_drawItem($row, $this->fieldArray);
379 // Traverse all pages selected:
380 foreach ($theRows as $sRow) {
381 if ($this->getBackendUser()->doesUserHaveAccess($sRow, 2)) {
382 $editUids[] = $sRow['uid'];
383 }
384 $out .= $this->pages_drawItem($sRow, $this->fieldArray);
385 }
386 $this->eCounter++;
387 }
388 // Header line is drawn
389 $theData = [];
390 $editIdList = implode(',', $editUids);
391 // Traverse fields (as set above) in order to create header values:
392 foreach ($this->fieldArray as $field) {
393 if ($editIdList
394 && isset($GLOBALS['TCA']['pages']['columns'][$field])
395 && $field != 'uid'
396 && !$this->pages_noEditColumns
397 ) {
398 $iTitle = sprintf(
399 $lang->getLL('editThisColumn'),
400 rtrim(trim($lang->sL(BackendUtility::getItemLabel('pages', $field))), ':')
401 );
402 $urlParameters = [
403 'edit' => [
404 'pages' => [
405 $editIdList => 'edit'
406 ]
407 ],
408 'columnsOnly' => $field,
409 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
410 ];
411 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
412 $eI = '<a href="' . htmlspecialchars($url)
413 . '" title="' . htmlspecialchars($iTitle) . '">'
414 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
415 } else {
416 $eI = '';
417 }
418 switch ($field) {
419 case 'title':
420 $theData[$field] = '&nbsp;<strong>'
421 . $lang->sL($GLOBALS['TCA']['pages']['columns'][$field]['label'])
422 . '</strong>' . $eI;
423 break;
424 case 'uid':
425 $theData[$field] = '&nbsp;<strong>ID:</strong>';
426 break;
427 default:
428 if (substr($field, 0, 6) == 'table_') {
429 $f2 = substr($field, 6);
430 if ($GLOBALS['TCA'][$f2]) {
431 $theData[$field] = '&nbsp;' .
432 '<span title="' .
433 htmlspecialchars($lang->sL($GLOBALS['TCA'][$f2]['ctrl']['title'])) .
434 '">' .
435 $this->iconFactory->getIconForRecord($f2, [], Icon::SIZE_SMALL)->render() .
436 '</span>';
437 }
438 } else {
439 $theData[$field] = '&nbsp;&nbsp;<strong>'
440 . htmlspecialchars($lang->sL($GLOBALS['TCA']['pages']['columns'][$field]['label']))
441 . '</strong>' . $eI;
442 }
443 }
444 }
445 // CSH:
446 $out = BackendUtility::cshItem($this->descrTable, ('func_' . $pKey), null, '<span class="btn btn-default btn-sm">|</span>') . '
447 <div class="table-fit">
448 <table class="table table-striped table-hover typo3-page-pages">' .
449 '<thead>' .
450 $this->addElement(1, '', $theData) .
451 '</thead>' .
452 '<tbody>' .
453 $out .
454 '</tbody>' .
455 '</table>
456 </div>';
457 }
458 return $out;
459 }
460
461 /**
462 * Renders Content Elements from the tt_content table from page id
463 *
464 * @param int $id Page id
465 * @return string HTML for the listing
466 */
467 public function getTable_tt_content($id)
468 {
469 $backendUser = $this->getBackendUser();
470 $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
471 ->getConnectionForTable('tt_content')
472 ->getExpressionBuilder();
473 $this->pageinfo = BackendUtility::readPageAccess($this->id, '');
474 $this->initializeLanguages();
475 $this->initializeClipboard();
476 $pageTitleParamForAltDoc = '&recTitle=' . rawurlencode(BackendUtility::getRecordTitle('pages', BackendUtility::getRecordWSOL('pages', $id), true));
477 /** @var $pageRenderer PageRenderer */
478 $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
479 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/DragDrop');
480 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
481 $userCanEditPage = $this->ext_CALC_PERMS & Permission::PAGE_EDIT && !empty($this->id) && ($backendUser->isAdmin() || (int)$this->pageinfo['editlock'] === 0);
482 if ($this->tt_contentConfig['languageColsPointer'] > 0) {
483 $userCanEditPage = $this->getBackendUser()->check('tables_modify', 'pages_language_overlay');
484 }
485 if ($userCanEditPage) {
486 $languageOverlayId = 0;
487 $overlayExpressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
488 ->getConnectionForTable('pages_language_overlay')
489 ->getExpressionBuilder();
490 $constraint = $overlayExpressionBuilder->eq(
491 'sys_language_uid',
492 (int)$this->tt_contentConfig['sys_language_uid']
493 );
494 $pageOverlayRecord = BackendUtility::getRecordsByField(
495 'pages_language_overlay',
496 'pid',
497 (int)$this->id,
498 $constraint
499 );
500 if (!empty($pageOverlayRecord[0]['uid'])) {
501 $languageOverlayId = $pageOverlayRecord[0]['uid'];
502 }
503 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/PageActions', 'function(PageActions) {
504 PageActions.setPageId(' . (int)$this->id . ');
505 PageActions.setLanguageOverlayId(' . $languageOverlayId . ');
506 PageActions.initializePageTitleRenaming();
507 }');
508 }
509 // Get labels for CTypes and tt_content element fields in general:
510 $this->CType_labels = [];
511 foreach ($GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'] as $val) {
512 $this->CType_labels[$val[1]] = $this->getLanguageService()->sL($val[0]);
513 }
514 $this->itemLabels = [];
515 foreach ($GLOBALS['TCA']['tt_content']['columns'] as $name => $val) {
516 $this->itemLabels[$name] = $this->getLanguageService()->sL($val['label']);
517 }
518 $languageColumn = [];
519 $out = '';
520
521 // Setting language list:
522 $langList = $this->tt_contentConfig['sys_language_uid'];
523 if ($this->tt_contentConfig['languageMode']) {
524 if ($this->tt_contentConfig['languageColsPointer']) {
525 $langList = '0,' . $this->tt_contentConfig['languageColsPointer'];
526 } else {
527 $langList = implode(',', array_keys($this->tt_contentConfig['languageCols']));
528 }
529 $languageColumn = [];
530 }
531 $langListArr = GeneralUtility::intExplode(',', $langList);
532 $defaultLanguageElementsByColumn = [];
533 $defLangBinding = [];
534 // For each languages... :
535 // If not languageMode, then we'll only be through this once.
536 foreach ($langListArr as $lP) {
537 $lP = (int)$lP;
538
539 if (!isset($this->contentElementCache[$lP])) {
540 $this->contentElementCache[$lP] = [];
541 }
542
543 if (count($langListArr) === 1 || $lP === 0) {
544 $showLanguage = $expressionBuilder->in('sys_language_uid', [$lP, -1]);
545 } else {
546 $showLanguage = $expressionBuilder->eq('sys_language_uid', $lP);
547 }
548 $cList = explode(',', $this->tt_contentConfig['cols']);
549 $content = [];
550 $head = [];
551
552 // Select content records per column
553 $contentRecordsPerColumn = $this->getContentRecordsPerColumn('table', $id, array_values($cList), $showLanguage);
554 // For each column, render the content into a variable:
555 foreach ($cList as $columnId) {
556 if (!isset($this->contentElementCache[$lP][$columnId])) {
557 $this->contentElementCache[$lP][$columnId] = [];
558 }
559
560 if (!$lP) {
561 $defaultLanguageElementsByColumn[$columnId] = [];
562 }
563 // Start wrapping div
564 $content[$columnId] .= '<div data-colpos="' . $columnId . '" data-language-uid="' . $lP . '" class="t3js-sortable t3js-sortable-lang t3js-sortable-lang-' . $lP . ' t3-page-ce-wrapper';
565 if (empty($contentRecordsPerColumn[$columnId])) {
566 $content[$columnId] .= ' t3-page-ce-empty';
567 }
568 $content[$columnId] .= '">';
569 // Add new content at the top most position
570 $link = '';
571 if ($this->getPageLayoutController()->contentIsNotLockedForEditors()
572 && (!$this->checkIfTranslationsExistInLanguage($contentRecordsPerColumn, $lP))
573 ) {
574 if ($this->option_newWizard) {
575 $urlParameters = [
576 'id' => $id,
577 'sys_language_uid' => $lP,
578 'colPos' => $columnId,
579 'uid_pid' => $id,
580 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
581 ];
582 $tsConfig = BackendUtility::getModTSconfig($id, 'mod');
583 $moduleName = isset($tsConfig['properties']['newContentElementWizard.']['override'])
584 ? $tsConfig['properties']['newContentElementWizard.']['override']
585 : 'new_content_element';
586 $url = BackendUtility::getModuleUrl($moduleName, $urlParameters);
587 } else {
588 $urlParameters = [
589 'edit' => [
590 'tt_content' => [
591 $id => 'new'
592 ]
593 ],
594 'defVals' => [
595 'tt_content' => [
596 'colPos' => $columnId,
597 'sys_language_uid' => $lP
598 ]
599 ],
600 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
601 ];
602 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
603 }
604
605 $link = '<a href="' . htmlspecialchars($url) . '" title="'
606 . htmlspecialchars($this->getLanguageService()->getLL('newContentElement')) . '" class="btn btn-default btn-sm">'
607 . $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render()
608 . ' '
609 . htmlspecialchars($this->getLanguageService()->getLL('content')) . '</a>';
610 }
611 if ($this->getBackendUser()->checkLanguageAccess($lP)) {
612 $content[$columnId] .= '
613 <div class="t3-page-ce t3js-page-ce" data-page="' . (int)$id . '" id="' . StringUtility::getUniqueId() . '">
614 <div class="t3js-page-new-ce t3-page-ce-wrapper-new-ce" id="colpos-' . $columnId . '-' . 'page-' . $id . '-' . StringUtility::getUniqueId() . '">'
615 . $link
616 . '</div>
617 <div class="t3-page-ce-dropzone-available t3js-page-ce-dropzone-available"></div>
618 </div>
619 ';
620 }
621 $editUidList = '';
622 if (!isset($contentRecordsPerColumn[$columnId]) || !is_array($contentRecordsPerColumn[$columnId])) {
623 $message = GeneralUtility::makeInstance(
624 FlashMessage::class,
625 $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:error.invalidBackendLayout'),
626 '',
627 FlashMessage::WARNING
628 );
629 $service = GeneralUtility::makeInstance(FlashMessageService::class);
630 $queue = $service->getMessageQueueByIdentifier();
631 $queue->addMessage($message);
632 } else {
633 $rowArr = $contentRecordsPerColumn[$columnId];
634 $this->generateTtContentDataArray($rowArr);
635
636 foreach ((array)$rowArr as $rKey => $row) {
637 $this->contentElementCache[$lP][$columnId][$row['uid']] = $row;
638 if ($this->tt_contentConfig['languageMode']) {
639 $languageColumn[$columnId][$lP] = $head[$columnId] . $content[$columnId];
640 if (!$this->defLangBinding) {
641 $languageColumn[$columnId][$lP] .= $this->newLanguageButton(
642 $this->getNonTranslatedTTcontentUids($defaultLanguageElementsByColumn[$columnId], $id, $lP),
643 $lP,
644 $columnId
645 );
646 }
647 }
648 if (is_array($row) && !VersionState::cast($row['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
649 $singleElementHTML = '';
650 if (!$lP && ($this->defLangBinding || $row['sys_language_uid'] != -1)) {
651 $defaultLanguageElementsByColumn[$columnId][] = (isset($row['_ORIG_uid']) ? $row['_ORIG_uid'] : $row['uid']);
652 }
653 $editUidList .= $row['uid'] . ',';
654 $disableMoveAndNewButtons = $this->defLangBinding && $lP > 0;
655 if (!$this->tt_contentConfig['languageMode']) {
656 $singleElementHTML .= '<div class="t3-page-ce-dragitem" id="' . StringUtility::getUniqueId() . '">';
657 }
658 $singleElementHTML .= $this->tt_content_drawHeader(
659 $row,
660 $this->tt_contentConfig['showInfo'] ? 15 : 5,
661 $disableMoveAndNewButtons,
662 true,
663 $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)
664 );
665 $innerContent = '<div ' . ($row['_ORIG_uid'] ? ' class="ver-element"' : '') . '>'
666 . $this->tt_content_drawItem($row) . '</div>';
667 $singleElementHTML .= '<div class="t3-page-ce-body-inner">' . $innerContent . '</div>'
668 . $this->tt_content_drawFooter($row);
669 $isDisabled = $this->isDisabled('tt_content', $row);
670 $statusHidden = $isDisabled ? ' t3-page-ce-hidden t3js-hidden-record' : '';
671 $displayNone = !$this->tt_contentConfig['showHidden'] && $isDisabled ? ' style="display: none;"' : '';
672 $highlightHeader = false;
673 if ($this->checkIfTranslationsExistInLanguage([], (int)$row['sys_language_uid']) && (int)$row['l18n_parent'] === 0) {
674 $highlightHeader = true;
675 }
676 $singleElementHTML = '<div class="t3-page-ce ' . ($highlightHeader ? 't3-page-ce-danger' : '') . ' t3js-page-ce t3js-page-ce-sortable ' . $statusHidden . '" id="element-tt_content-'
677 . $row['uid'] . '" data-table="tt_content" data-uid="' . $row['uid'] . '"' . $displayNone . '>' . $singleElementHTML . '</div>';
678
679 if ($this->tt_contentConfig['languageMode']) {
680 $singleElementHTML .= '<div class="t3-page-ce t3js-page-ce">';
681 }
682 $singleElementHTML .= '<div class="t3js-page-new-ce t3-page-ce-wrapper-new-ce" id="colpos-' . $columnId . '-' . 'page-' . $id .
683 '-' . StringUtility::getUniqueId() . '">';
684 // Add icon "new content element below"
685 if (!$disableMoveAndNewButtons
686 && $this->getPageLayoutController()->contentIsNotLockedForEditors()
687 && $this->getBackendUser()->checkLanguageAccess($lP)
688 && (!$this->checkIfTranslationsExistInLanguage($contentRecordsPerColumn, $lP))
689 ) {
690 // New content element:
691 if ($this->option_newWizard) {
692 $urlParameters = [
693 'id' => $row['pid'],
694 'sys_language_uid' => $row['sys_language_uid'],
695 'colPos' => $row['colPos'],
696 'uid_pid' => -$row['uid'],
697 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
698 ];
699 $tsConfig = BackendUtility::getModTSconfig($row['pid'], 'mod');
700 $moduleName = isset($tsConfig['properties']['newContentElementWizard.']['override'])
701 ? $tsConfig['properties']['newContentElementWizard.']['override']
702 : 'new_content_element';
703 $url = BackendUtility::getModuleUrl($moduleName, $urlParameters);
704 } else {
705 $urlParameters = [
706 'edit' => [
707 'tt_content' => [
708 -$row['uid'] => 'new'
709 ]
710 ],
711 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
712 ];
713 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
714 }
715 $singleElementHTML .= '
716 <a href="' . htmlspecialchars($url) . '" title="'
717 . htmlspecialchars($this->getLanguageService()->getLL('newContentElement')) . '" class="btn btn-default btn-sm">'
718 . $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render()
719 . ' '
720 . htmlspecialchars($this->getLanguageService()->getLL('content')) . '</a>
721 ';
722 }
723 $singleElementHTML .= '</div></div><div class="t3-page-ce-dropzone-available t3js-page-ce-dropzone-available"></div></div>';
724 if ($this->defLangBinding && $this->tt_contentConfig['languageMode']) {
725 $defLangBinding[$columnId][$lP][$row[$lP ? 'l18n_parent' : 'uid']] = $singleElementHTML;
726 } else {
727 $content[$columnId] .= $singleElementHTML;
728 }
729 } else {
730 unset($rowArr[$rKey]);
731 }
732 }
733 $content[$columnId] .= '</div>';
734 $colTitle = BackendUtility::getProcessedValue('tt_content', 'colPos', $columnId);
735 $tcaItems = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $id, $this);
736 foreach ($tcaItems as $item) {
737 if ($item[1] == $columnId) {
738 $colTitle = $this->getLanguageService()->sL($item[0]);
739 }
740 }
741
742 $pasteP = ['colPos' => $columnId, 'sys_language_uid' => $lP];
743 $editParam = $this->doEdit && !empty($rowArr)
744 ? '&edit[tt_content][' . $editUidList . ']=edit' . $pageTitleParamForAltDoc
745 : '';
746 $head[$columnId] .= $this->tt_content_drawColHeader($colTitle, $editParam, '', $pasteP);
747 }
748 }
749 // For each column, fit the rendered content into a table cell:
750 $out = '';
751 if ($this->tt_contentConfig['languageMode']) {
752 // in language mode process the content elements, but only fill $languageColumn. output will be generated later
753 $sortedLanguageColumn = [];
754 foreach ($cList as $columnId) {
755 $languageColumn[$columnId][$lP] = $head[$columnId] . $content[$columnId];
756 if (!$this->defLangBinding) {
757 $languageColumn[$columnId][$lP] .= $this->newLanguageButton(
758 $this->getNonTranslatedTTcontentUids($defaultLanguageElementsByColumn[$columnId], $id, $lP),
759 $lP,
760 $columnId
761 );
762 }
763 // We sort $languageColumn again according to $cList as it may contain data already from above.
764 $sortedLanguageColumn[$columnId] = $languageColumn[$columnId];
765 }
766 $languageColumn = $sortedLanguageColumn;
767 } else {
768 $backendLayout = $this->getBackendLayoutView()->getSelectedBackendLayout($this->id);
769 // GRID VIEW:
770 $grid = '<div class="t3-grid-container"><table border="0" cellspacing="0" cellpadding="0" width="100%" class="t3-page-columns t3-grid-table t3js-page-columns">';
771 // Add colgroups
772 $colCount = (int)$backendLayout['__config']['backend_layout.']['colCount'];
773 $rowCount = (int)$backendLayout['__config']['backend_layout.']['rowCount'];
774 $grid .= '<colgroup>';
775 for ($i = 0; $i < $colCount; $i++) {
776 $grid .= '<col style="width:' . 100 / $colCount . '%"></col>';
777 }
778 $grid .= '</colgroup>';
779 // Cycle through rows
780 for ($row = 1; $row <= $rowCount; $row++) {
781 $rowConfig = $backendLayout['__config']['backend_layout.']['rows.'][$row . '.'];
782 if (!isset($rowConfig)) {
783 continue;
784 }
785 $grid .= '<tr>';
786 for ($col = 1; $col <= $colCount; $col++) {
787 $columnConfig = $rowConfig['columns.'][$col . '.'];
788 if (!isset($columnConfig)) {
789 continue;
790 }
791 // Which tt_content colPos should be displayed inside this cell
792 $columnKey = (int)$columnConfig['colPos'];
793 // Render the grid cell
794 $colSpan = (int)$columnConfig['colspan'];
795 $rowSpan = (int)$columnConfig['rowspan'];
796 $grid .= '<td valign="top"' .
797 ($colSpan > 0 ? ' colspan="' . $colSpan . '"' : '') .
798 ($rowSpan > 0 ? ' rowspan="' . $rowSpan . '"' : '') .
799 ' data-colpos="' . (int)$columnConfig['colPos'] . '" data-language-uid="' . $lP . '" class="t3js-page-lang-column-' . $lP . ' t3js-page-column t3-grid-cell t3-page-column t3-page-column-' . $columnKey .
800 ((!isset($columnConfig['colPos']) || $columnConfig['colPos'] === '') ? ' t3-grid-cell-unassigned' : '') .
801 ((isset($columnConfig['colPos']) && $columnConfig['colPos'] !== '' && !$head[$columnKey]) || !GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos']) ? ' t3-grid-cell-restricted' : '') .
802 ($colSpan > 0 ? ' t3-gridCell-width' . $colSpan : '') .
803 ($rowSpan > 0 ? ' t3-gridCell-height' . $rowSpan : '') . '">';
804
805 // Draw the pre-generated header with edit and new buttons if a colPos is assigned.
806 // If not, a new header without any buttons will be generated.
807 if (isset($columnConfig['colPos']) && $columnConfig['colPos'] !== '' && $head[$columnKey]
808 && GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
809 ) {
810 $grid .= $head[$columnKey] . $content[$columnKey];
811 } elseif (isset($columnConfig['colPos']) && $columnConfig['colPos'] !== ''
812 && GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
813 ) {
814 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->getLL('noAccess'), '', '');
815 } elseif (isset($columnConfig['colPos']) && $columnConfig['colPos'] !== ''
816 && !GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
817 ) {
818 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->sL($columnConfig['name']) .
819 ' (' . $this->getLanguageService()->getLL('noAccess') . ')', '', '');
820 } elseif (isset($columnConfig['name']) && $columnConfig['name'] !== '') {
821 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->sL($columnConfig['name'])
822 . ' (' . $this->getLanguageService()->getLL('notAssigned') . ')', '', '');
823 } else {
824 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->getLL('notAssigned'), '', '');
825 }
826
827 $grid .= '</td>';
828 }
829 $grid .= '</tr>';
830 }
831 $out .= $grid . '</table></div>';
832 }
833 // CSH:
834 $out .= BackendUtility::cshItem($this->descrTable, 'columns_multi', null, '<span class="btn btn-default btn-sm">|</span>');
835 }
836 // If language mode, then make another presentation:
837 // Notice that THIS presentation will override the value of $out!
838 // But it needs the code above to execute since $languageColumn is filled with content we need!
839 if ($this->tt_contentConfig['languageMode']) {
840 // Get language selector:
841 $languageSelector = $this->languageSelector($id);
842 // Reset out - we will make new content here:
843 $out = '';
844 // Traverse languages found on the page and build up the table displaying them side by side:
845 $cCont = [];
846 $sCont = [];
847 foreach ($langListArr as $lP) {
848 // Header:
849 $lP = (int)$lP;
850 $cCont[$lP] = '
851 <td valign="top" class="t3-page-column" data-language-uid="' . $lP . '">
852 <h2>' . htmlspecialchars($this->tt_contentConfig['languageCols'][$lP]) . '</h2>
853 </td>';
854
855 // "View page" icon is added:
856 $viewLink = '';
857 if (!VersionState::cast($this->getPageLayoutController()->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
858 $onClick = BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id), '', '', ('&L=' . $lP));
859 $viewLink = '<a href="#" class="btn btn-default btn-sm" onclick="' . htmlspecialchars($onClick) . '" title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage')) . '">' . $this->iconFactory->getIcon('actions-view', Icon::SIZE_SMALL)->render() . '</a>';
860 }
861 // Language overlay page header:
862 if ($lP) {
863 list($lpRecord) = BackendUtility::getRecordsByField('pages_language_overlay', 'pid', $id, 'AND sys_language_uid=' . $lP);
864 BackendUtility::workspaceOL('pages_language_overlay', $lpRecord);
865 $params = '&edit[pages_language_overlay][' . $lpRecord['uid'] . ']=edit&overrideVals[pages_language_overlay][sys_language_uid]=' . $lP;
866 $recordIcon = BackendUtility::wrapClickMenuOnIcon(
867 $this->iconFactory->getIconForRecord('pages_language_overlay', $lpRecord, Icon::SIZE_SMALL)->render(),
868 'pages_language_overlay',
869 $lpRecord['uid']
870 );
871 $urlParameters = [
872 'edit' => [
873 'pages_language_overlay' => [
874 $lpRecord['uid'] => 'edit'
875 ]
876 ],
877 'overrideVals' => [
878 'pages_language_overlay' => [
879 'sys_language_uid' => $lP
880 ]
881 ],
882 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
883 ];
884 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
885 $editLink = ($this->getBackendUser()->check('tables_modify', 'pages_language_overlay')
886 ? '<a href="' . htmlspecialchars($url) . '" class="btn btn-default btn-sm"'
887 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('edit')) . '">'
888 . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>'
889 : ''
890 );
891
892 $lPLabel =
893 '<div class="btn-group">'
894 . $viewLink
895 . $editLink
896 . '</div>'
897 . ' ' . $recordIcon . ' ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($lpRecord['title'], 20));
898 } else {
899 $editLink = '';
900 $recordIcon = '';
901 if ($this->getBackendUser()->checkLanguageAccess(0)) {
902 $recordIcon = BackendUtility::wrapClickMenuOnIcon(
903 $this->iconFactory->getIconForRecord('pages', $this->pageRecord, Icon::SIZE_SMALL)->render(), 'pages', $this->id);
904 $urlParameters = [
905 'edit' => [
906 'pages' => [
907 $this->id => 'edit'
908 ]
909 ],
910 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
911 ];
912 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
913 $editLink = ($this->getBackendUser()->check('tables_modify', 'pages_language_overlay')
914 ? '<a href="' . htmlspecialchars($url) . '" class="btn btn-default btn-sm"'
915 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('edit')) . '">'
916 . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>'
917 : ''
918 );
919 }
920
921 $lPLabel =
922 '<div class="btn-group">'
923 . $viewLink
924 . $editLink
925 . '</div>'
926 . ' ' . $recordIcon . ' ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($this->pageRecord['title'], 20));
927 }
928 $sCont[$lP] = '
929 <td nowrap="nowrap" class="t3-page-column t3-page-lang-label">' . $lPLabel . '</td>';
930 }
931 // Add headers:
932 $out .= '<tr>' . implode($cCont) . '</tr>';
933 $out .= '<tr>' . implode($sCont) . '</tr>';
934 unset($cCont, $sCont);
935
936 // Traverse previously built content for the columns:
937 foreach ($languageColumn as $cKey => $cCont) {
938 $out .= '<tr>';
939 foreach ($cCont as $languageId => $columnContent) {
940 $out .= '<td valign="top" class="t3-grid-cell t3-page-column t3js-page-column t3js-page-lang-column t3js-page-lang-column-' . $languageId . '">' . $columnContent . '</td>';
941 }
942 $out .= '</tr>';
943 if ($this->defLangBinding) {
944 // "defLangBinding" mode
945 foreach ($defaultLanguageElementsByColumn[$cKey] as $defUid) {
946 $cCont = [];
947 foreach ($langListArr as $lP) {
948 $cCont[] = $defLangBinding[$cKey][$lP][$defUid] . $this->newLanguageButton(
949 $this->getNonTranslatedTTcontentUids([$defUid], $id, $lP),
950 $lP,
951 $cKey
952 );
953 }
954 $out .= '
955 <tr>
956 <td valign="top" class="t3-grid-cell">' . implode(('</td>' . '
957 <td valign="top" class="t3-grid-cell">'), $cCont) . '</td>
958 </tr>';
959 }
960 }
961 }
962 // Finally, wrap it all in a table and add the language selector on top of it:
963 $out = $languageSelector . '
964 <div class="t3-grid-container">
965 <table cellpadding="0" cellspacing="0" class="t3-page-columns t3-grid-table t3js-page-columns">
966 ' . $out . '
967 </table>
968 </div>';
969 // CSH:
970 $out .= BackendUtility::cshItem($this->descrTable, 'language_list', null, '<span class="btn btn-default btn-sm">|</span>');
971 }
972
973 return $out;
974 }
975
976 /**********************************
977 *
978 * Generic listing of items
979 *
980 **********************************/
981 /**
982 * Creates a standard list of elements from a table.
983 *
984 * @param string $table Table name
985 * @param int $id Page id.
986 * @param string $fList Comma list of fields to display
987 * @param bool $icon If TRUE, icon is shown
988 * @param string $addWhere Additional WHERE-clauses.
989 * @return string HTML table
990 */
991 public function makeOrdinaryList($table, $id, $fList, $icon = false, $addWhere = '')
992 {
993 // Initialize
994 $addWhere = empty($addWhere) ? [] : [QueryHelper::stripLogicalOperatorPrefix($addWhere)];
995 $queryBuilder = $this->getQueryBuilder($table, $id, $addWhere);
996 $this->setTotalItems($table, $id, $addWhere);
997 $dbCount = 0;
998 $result = false;
999 // Make query for records if there were any records found in the count operation
1000 if ($this->totalItems) {
1001 $result = $queryBuilder->execute();
1002 // Will return FALSE, if $result is invalid
1003 $dbCount = $result->rowCount();
1004 }
1005 // If records were found, render the list
1006 if (!$dbCount) {
1007 return '';
1008 }
1009 // Set fields
1010 $out = '';
1011 $this->fieldArray = GeneralUtility::trimExplode(',', '__cmds__,' . $fList . ',__editIconLink__', true);
1012 $theData = [];
1013 $theData = $this->headerFields($this->fieldArray, $table, $theData);
1014 // Title row
1015 $localizedTableTitle = htmlspecialchars($this->getLanguageService()->sL($GLOBALS['TCA'][$table]['ctrl']['title']));
1016 $out .= '<tr><th class="col-icon"></th>'
1017 . '<th colspan="' . (count($theData) - 2) . '"><span class="c-table">'
1018 . $localizedTableTitle . '</span> (' . $dbCount . ')</td>' . '<td class="col-icon"></td>'
1019 . '</tr>';
1020 // Column's titles
1021 if ($this->doEdit) {
1022 $urlParameters = [
1023 'edit' => [
1024 $table => [
1025 $this->id => 'new'
1026 ]
1027 ],
1028 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1029 ];
1030 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1031 $theData['__cmds__'] = '<a href="' . htmlspecialchars($url) . '" '
1032 . 'title="' . htmlspecialchars($this->getLanguageService()->getLL('new')) . '">'
1033 . $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render() . '</a>';
1034 }
1035 $out .= $this->addElement(1, '', $theData, ' class="c-headLine"', 15, '', 'th');
1036 // Render Items
1037 $this->eCounter = $this->firstElementNumber;
1038 while ($row = $result->fetch()) {
1039 BackendUtility::workspaceOL($table, $row);
1040 if (is_array($row)) {
1041 list($flag, $code) = $this->fwd_rwd_nav();
1042 $out .= $code;
1043 if ($flag) {
1044 $Nrow = [];
1045 // Setting icons links
1046 if ($icon) {
1047 $Nrow['__cmds__'] = $this->getIcon($table, $row);
1048 }
1049 // Get values:
1050 $Nrow = $this->dataFields($this->fieldArray, $table, $row, $Nrow);
1051 // Attach edit icon
1052 if ($this->doEdit && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)) {
1053 $urlParameters = [
1054 'edit' => [
1055 $table => [
1056 $row['uid'] => 'edit'
1057 ]
1058 ],
1059 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1060 ];
1061 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1062 $Nrow['__editIconLink__'] = '<a href="' . htmlspecialchars($url)
1063 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('edit')) . '">'
1064 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1065 } else {
1066 $Nrow['__editIconLink__'] = $this->noEditIcon();
1067 }
1068 $out .= $this->addElement(1, '', $Nrow);
1069 }
1070 $this->eCounter++;
1071 }
1072 }
1073 // Wrap it all in a table:
1074 $out = '
1075 <!--
1076 Standard list of table "' . $table . '"
1077 -->
1078 <div class="table-fit"><table class="table table-hover table-striped">
1079 ' . $out . '
1080 </table></div>';
1081 return $out;
1082 }
1083
1084 /**
1085 * Adds content to all data fields in $out array
1086 *
1087 * Each field name in $fieldArr has a special feature which is that the field name can be specified as more field names.
1088 * Eg. "field1,field2;field3".
1089 * Field 2 and 3 will be shown in the same cell of the table separated by <br /> while field1 will have its own cell.
1090 *
1091 * @param array $fieldArr Array of fields to display
1092 * @param string $table Table name
1093 * @param array $row Record array
1094 * @param array $out Array to which the data is added
1095 * @return array $out array returned after processing.
1096 * @see makeOrdinaryList()
1097 */
1098 public function dataFields($fieldArr, $table, $row, $out = [])
1099 {
1100 // Check table validity
1101 if (!isset($GLOBALS['TCA'][$table])) {
1102 return $out;
1103 }
1104
1105 $thumbsCol = $GLOBALS['TCA'][$table]['ctrl']['thumbnail'];
1106 // Traverse fields
1107 foreach ($fieldArr as $fieldName) {
1108 if ($GLOBALS['TCA'][$table]['columns'][$fieldName]) {
1109 // Each field has its own cell (if configured in TCA)
1110 // If the column is a thumbnail column:
1111 if ($fieldName == $thumbsCol) {
1112 $out[$fieldName] = $this->thumbCode($row, $table, $fieldName);
1113 } else {
1114 // ... otherwise just render the output:
1115 $out[$fieldName] = nl2br(htmlspecialchars(trim(GeneralUtility::fixed_lgd_cs(
1116 BackendUtility::getProcessedValue($table, $fieldName, $row[$fieldName], 0, 0, 0, $row['uid']),
1117 250
1118 ))));
1119 }
1120 } else {
1121 // Each field is separated by <br /> and shown in the same cell (If not a TCA field, then explode
1122 // the field name with ";" and check each value there as a TCA configured field)
1123 $theFields = explode(';', $fieldName);
1124 // Traverse fields, separated by ";" (displayed in a single cell).
1125 foreach ($theFields as $fName2) {
1126 if ($GLOBALS['TCA'][$table]['columns'][$fName2]) {
1127 $out[$fieldName] .= '<strong>' . htmlspecialchars($this->getLanguageService()->sL(
1128 $GLOBALS['TCA'][$table]['columns'][$fName2]['label']
1129 )) . '</strong>' . '&nbsp;&nbsp;' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(
1130 BackendUtility::getProcessedValue($table, $fName2, $row[$fName2], 0, 0, 0, $row['uid']),
1131 25
1132 )) . '<br />';
1133 }
1134 }
1135 }
1136 // If no value, add a nbsp.
1137 if (!$out[$fieldName]) {
1138 $out[$fieldName] = '&nbsp;';
1139 }
1140 // Wrap in dimmed-span tags if record is "disabled"
1141 if ($this->isDisabled($table, $row)) {
1142 $out[$fieldName] = '<span class="text-muted">' . $out[$fieldName] . '</span>';
1143 }
1144 }
1145 return $out;
1146 }
1147
1148 /**
1149 * Header fields made for the listing of records
1150 *
1151 * @param array $fieldArr Field names
1152 * @param string $table The table name
1153 * @param array $out Array to which the headers are added.
1154 * @return array $out returned after addition of the header fields.
1155 * @see makeOrdinaryList()
1156 */
1157 public function headerFields($fieldArr, $table, $out = [])
1158 {
1159 foreach ($fieldArr as $fieldName) {
1160 $ll = htmlspecialchars($this->getLanguageService()->sL($GLOBALS['TCA'][$table]['columns'][$fieldName]['label']));
1161 $out[$fieldName] = $ll ? $ll : '&nbsp;';
1162 }
1163 return $out;
1164 }
1165
1166 /**
1167 * Gets content records per column.
1168 * This is required for correct workspace overlays.
1169 *
1170 * @param string $table UNUSED (will always be queried from tt_content)
1171 * @param int $id Page Id to be used (not used at all, but part of the API, see $this->pidSelect)
1172 * @param array $columns colPos values to be considered to be shown
1173 * @param string $additionalWhereClause Additional where clause for database select
1174 * @return array Associative array for each column (colPos)
1175 */
1176 protected function getContentRecordsPerColumn($table, $id, array $columns, $additionalWhereClause = '')
1177 {
1178 $columns = array_map('intval', $columns);
1179 $contentRecordsPerColumn = array_fill_keys($columns, []);
1180
1181 $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
1182 ->getQueryBuilderForTable('tt_content')
1183 ->expr();
1184
1185 $queryBuilder = $this->getQueryBuilder(
1186 'tt_content',
1187 $id,
1188 [
1189 $expressionBuilder->in('colPos', $columns),
1190 $additionalWhereClause
1191 ]
1192 );
1193
1194 // Traverse any selected elements and render their display code:
1195 $results = $this->getResult($queryBuilder->execute());
1196
1197 foreach ($results as $record) {
1198 $columnValue = $record['colPos'];
1199 $contentRecordsPerColumn[$columnValue][] = $record;
1200 }
1201
1202 return $contentRecordsPerColumn;
1203 }
1204
1205 /**********************************
1206 *
1207 * Additional functions; Pages
1208 *
1209 **********************************/
1210
1211 /**
1212 * Adds pages-rows to an array, selecting recursively in the page tree.
1213 *
1214 * @param int $pid Starting page id to select from
1215 * @param string $iconPrefix Prefix for icon code.
1216 * @param int $depth Depth (decreasing)
1217 * @param array $rows Array which will accumulate page rows
1218 * @return array $rows with added rows.
1219 */
1220 protected function getPageRecordsRecursive(int $pid, int $depth, string $iconPrefix = '', array $rows = []): array
1221 {
1222 $depth--;
1223 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
1224 $queryBuilder->getRestrictions()
1225 ->removeAll()
1226 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
1227 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
1228
1229 $queryBuilder
1230 ->select('*')
1231 ->from('pages')
1232 ->where(
1233 $queryBuilder->expr()->eq('pid', (int)$pid),
1234 $this->getBackendUser()->getPagePermsClause(1)
1235 );
1236
1237 if (!empty($GLOBALS['TCA']['pages']['ctrl']['sortby'])) {
1238 $queryBuilder->orderBy($GLOBALS['TCA']['pages']['ctrl']['sortby']);
1239 }
1240
1241 if ($depth >= 0) {
1242 $result = $queryBuilder->execute();
1243 $rowCount = $result->rowCount();
1244 $count = 0;
1245 while ($row = $result->fetch()) {
1246 BackendUtility::workspaceOL('pages', $row);
1247 if (is_array($row)) {
1248 $count++;
1249 $row['treeIcons'] = $iconPrefix
1250 . '<span class="treeline-icon treeline-icon-join'
1251 . ($rowCount === $count ? 'bottom' : '')
1252 . '"></span>';
1253 $rows[] = $row;
1254 // Get the branch
1255 $spaceOutIcons = '<span class="treeline-icon treeline-icon-'
1256 . ($rowCount === $count ? 'clear' : 'line')
1257 . '"></span>';
1258 $rows = $this->getPageRecordsRecursive(
1259 $row['uid'],
1260 $row['php_tree_stop'] ? 0 : $depth,
1261 $iconPrefix . $spaceOutIcons,
1262 $rows
1263 );
1264 }
1265 }
1266 } else {
1267 $count = (int)$queryBuilder->count('uid')->execute()->fetchColumn(0);
1268 if ($count) {
1269 $this->plusPages[$pid] = $count;
1270 }
1271 }
1272
1273 return $rows;
1274 }
1275
1276 /**
1277 * Adds pages-rows to an array, selecting recursively in the page tree.
1278 *
1279 * @param array $theRows Array which will accumulate page rows
1280 * @param int $pid Pid to select from
1281 * @param string $qWhere Query-where clause
1282 * @param string $treeIcons Prefixed icon code.
1283 * @param int $depth Depth (decreasing)
1284 * @return array $theRows, but with added rows.
1285 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
1286 */
1287 public function pages_getTree($theRows, $pid, $qWhere, $treeIcons, $depth)
1288 {
1289 GeneralUtility::logDeprecatedFunction();
1290 $depth--;
1291 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
1292 $queryBuilder->getRestrictions()
1293 ->removeAll();
1294 $queryBuilder
1295 ->select('*')
1296 ->from('pages')
1297 ->where($queryBuilder->expr()->eq('pid', (int)$pid));
1298
1299 if (!empty($GLOBALS['TCA']['pages']['ctrl']['sortby'])) {
1300 $queryBuilder->orderBy($GLOBALS['TCA']['pages']['ctrl']['sortby']);
1301 }
1302
1303 if (!empty($qWhere)) {
1304 $queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($qWhere));
1305 }
1306
1307 if ($depth >= 0) {
1308 $result = $queryBuilder->execute();
1309 $rc = $result->rowCount();
1310 $c = 0;
1311 while ($row = $result->fetch()) {
1312 BackendUtility::workspaceOL('pages', $row);
1313 if (is_array($row)) {
1314 $c++;
1315 $row['treeIcons'] = $treeIcons . '<span class="treeline-icon treeline-icon-join' . ($rc === $c ? 'bottom' : '') . '"></span>';
1316 $theRows[] = $row;
1317 // Get the branch
1318 $spaceOutIcons = '<span class="treeline-icon treeline-icon-' . ($rc === $c ? 'clear' : 'line') . '"></span>';
1319 $theRows = $this->pages_getTree($theRows, $row['uid'], $qWhere, $treeIcons . $spaceOutIcons,
1320 $row['php_tree_stop'] ? 0 : $depth);
1321 }
1322 }
1323 } else {
1324 $count = (int)$queryBuilder->count('uid')->execute()->fetchColumn(0);
1325 if ($count) {
1326 $this->plusPages[$pid] = $count;
1327 }
1328 }
1329 return $theRows;
1330 }
1331
1332 /**
1333 * Adds a list item for the pages-rendering
1334 *
1335 * @param array $row Record array
1336 * @param array $fieldArr Field list
1337 * @return string HTML for the item
1338 */
1339 public function pages_drawItem($row, $fieldArr)
1340 {
1341 // Initialization
1342 $theIcon = $this->getIcon('pages', $row);
1343 // Preparing and getting the data-array
1344 $theData = [];
1345 foreach ($fieldArr as $field) {
1346 switch ($field) {
1347 case 'title':
1348 $red = $this->plusPages[$row['uid']] ? '<span class="text-danger"><strong>+</strong></span>' : '';
1349 $pTitle = htmlspecialchars(BackendUtility::getProcessedValue('pages', $field, $row[$field], 20));
1350 if ($red) {
1351 $pTitle = '<a href="'
1352 . htmlspecialchars($this->script . ((strpos($this->script, '?') !== false) ? '&' : '?')
1353 . 'id=' . $row['uid']) . '">' . $pTitle . '</a>';
1354 }
1355 $theData[$field] = $row['treeIcons'] . $theIcon . $red . $pTitle . '&nbsp;&nbsp;';
1356 break;
1357 case 'php_tree_stop':
1358 // Intended fall through
1359 case 'TSconfig':
1360 $theData[$field] = $row[$field] ? '&nbsp;<strong>x</strong>' : '&nbsp;';
1361 break;
1362 case 'uid':
1363 if ($this->getBackendUser()->doesUserHaveAccess($row, 2) && $row['uid'] > 0) {
1364 $urlParameters = [
1365 'edit' => [
1366 'pages' => [
1367 $row['uid'] => 'edit'
1368 ]
1369 ],
1370 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1371 ];
1372 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1373 $eI = '<a href="' . htmlspecialchars($url)
1374 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('editThisPage')) . '">'
1375 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1376 } else {
1377 $eI = '';
1378 }
1379 $theData[$field] = '<span align="right">' . $row['uid'] . $eI . '</span>';
1380 break;
1381 case 'shortcut':
1382 case 'shortcut_mode':
1383 if ((int)$row['doktype'] === \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SHORTCUT) {
1384 $theData[$field] = $this->getPagesTableFieldValue($field, $row);
1385 }
1386 break;
1387 default:
1388 if (substr($field, 0, 6) == 'table_') {
1389 $f2 = substr($field, 6);
1390 if ($GLOBALS['TCA'][$f2]) {
1391 $c = $this->numberOfRecords($f2, $row['uid']);
1392 $theData[$field] = '&nbsp;&nbsp;' . ($c ? $c : '');
1393 }
1394 } else {
1395 $theData[$field] = $this->getPagesTableFieldValue($field, $row);
1396 }
1397 }
1398 }
1399 $this->addElement_tdParams['title'] = $row['_CSSCLASS'] ? ' class="' . $row['_CSSCLASS'] . '"' : '';
1400 return $this->addElement(1, '', $theData);
1401 }
1402
1403 /**
1404 * Returns the HTML code for rendering a field in the pages table.
1405 * The row value is processed to a human readable form and the result is parsed through htmlspecialchars().
1406 *
1407 * @param string $field The name of the field of which the value should be rendered.
1408 * @param array $row The pages table row as an associative array.
1409 * @return string The rendered table field value.
1410 */
1411 protected function getPagesTableFieldValue($field, array $row)
1412 {
1413 return '&nbsp;&nbsp;' . htmlspecialchars(BackendUtility::getProcessedValue('pages', $field, $row[$field]));
1414 }
1415
1416 /**********************************
1417 *
1418 * Additional functions; Content Elements
1419 *
1420 **********************************/
1421 /**
1422 * Draw header for a content element column:
1423 *
1424 * @param string $colName Column name
1425 * @param string $editParams Edit params (Syntax: &edit[...] for FormEngine)
1426 * @param string $newParams New element params (Syntax: &edit[...] for FormEngine) OBSOLETE
1427 * @param array|NULL $pasteParams Paste element params (i.e. array(colPos => 1, sys_language_uid => 2))
1428 * @return string HTML table
1429 */
1430 public function tt_content_drawColHeader($colName, $editParams, $newParams, array $pasteParams = null)
1431 {
1432 $iconsArr = [];
1433 // Create command links:
1434 if ($this->tt_contentConfig['showCommands']) {
1435 // Edit whole of column:
1436 if ($editParams && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT) && $this->getBackendUser()->checkLanguageAccess(0)) {
1437 $iconsArr['edit'] = '<a href="#" onclick="'
1438 . htmlspecialchars(BackendUtility::editOnClick($editParams)) . '" title="'
1439 . htmlspecialchars($this->getLanguageService()->getLL('editColumn')) . '">'
1440 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1441 }
1442 if ($pasteParams) {
1443 $elFromTable = $this->clipboard->elFromTable('tt_content');
1444 if (!empty($elFromTable) && $this->getPageLayoutController()->pageIsNotLockedForEditors()) {
1445 $iconsArr['paste'] =
1446 '<a href="' . htmlspecialchars($this->clipboard->pasteUrl('tt_content', $this->id, true, $pasteParams)) . '"'
1447 . ' class="t3js-modal-trigger"'
1448 . ' data-severity="warning"'
1449 . ' data-title="' . htmlspecialchars($this->getLanguageService()->getLL('pasteIntoColumn')) . '"'
1450 . ' data-content="' . htmlspecialchars($this->clipboard->confirmMsgText('pages', $this->pageRecord, 'into', $elFromTable, $colName)) . '"'
1451 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('pasteIntoColumn')) . '">'
1452 . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render()
1453 . '</a>';
1454 }
1455 }
1456 }
1457 $icons = '';
1458 if (!empty($iconsArr)) {
1459 $icons = '<div class="t3-page-column-header-icons">' . implode('', $iconsArr) . '</div>';
1460 }
1461 // Create header row:
1462 $out = '<div class="t3-page-column-header">
1463 ' . $icons . '
1464 <div class="t3-page-column-header-label">' . htmlspecialchars($colName) . '</div>
1465 </div>';
1466 return $out;
1467 }
1468
1469 /**
1470 * Draw the footer for a single tt_content element
1471 *
1472 * @param array $row Record array
1473 * @return string HTML of the footer
1474 * @throws \UnexpectedValueException
1475 */
1476 protected function tt_content_drawFooter(array $row)
1477 {
1478 $content = '';
1479 // Get processed values:
1480 $info = [];
1481 $this->getProcessedValue('tt_content', 'starttime,endtime,fe_group,spaceBefore,spaceAfter', $row, $info);
1482
1483 // Content element annotation
1484 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['descriptionColumn'])) {
1485 $info[] = htmlspecialchars($row[$GLOBALS['TCA']['tt_content']['ctrl']['descriptionColumn']]);
1486 }
1487
1488 // Call drawFooter hooks
1489 $drawFooterHooks = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawFooter'];
1490 if (is_array($drawFooterHooks)) {
1491 foreach ($drawFooterHooks as $hookClass) {
1492 $hookObject = GeneralUtility::getUserObj($hookClass);
1493 if (!$hookObject instanceof PageLayoutViewDrawFooterHookInterface) {
1494 throw new \UnexpectedValueException($hookClass . ' must implement interface ' . PageLayoutViewDrawFooterHookInterface::class, 1404378171);
1495 }
1496 $hookObject->preProcess($this, $info, $row);
1497 }
1498 }
1499
1500 // Display info from records fields:
1501 if (!empty($info)) {
1502 $content = '<div class="t3-page-ce-info">
1503 ' . implode('<br>', $info) . '
1504 </div>';
1505 }
1506 // Wrap it
1507 if (!empty($content)) {
1508 $content = '<div class="t3-page-ce-footer">' . $content . '</div>';
1509 }
1510 return $content;
1511 }
1512
1513 /**
1514 * Draw the header for a single tt_content element
1515 *
1516 * @param array $row Record array
1517 * @param int $space Amount of pixel space above the header. UNUSED
1518 * @param bool $disableMoveAndNewButtons If set the buttons for creating new elements and moving up and down are not shown.
1519 * @param bool $langMode If set, we are in language mode and flags will be shown for languages
1520 * @param bool $dragDropEnabled If set the move button must be hidden
1521 * @return string HTML table with the record header.
1522 */
1523 public function tt_content_drawHeader($row, $space = 0, $disableMoveAndNewButtons = false, $langMode = false, $dragDropEnabled = false)
1524 {
1525 $out = '';
1526 // If show info is set...;
1527 if ($this->tt_contentConfig['showInfo'] && $this->getBackendUser()->recordEditAccessInternals('tt_content', $row)) {
1528 // Render control panel for the element:
1529 if ($this->tt_contentConfig['showCommands'] && $this->doEdit) {
1530 // Edit content element:
1531 $urlParameters = [
1532 'edit' => [
1533 'tt_content' => [
1534 $this->tt_contentData['nextThree'][$row['uid']] => 'edit'
1535 ]
1536 ],
1537 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') . '#element-tt_content-' . $row['uid'],
1538 ];
1539 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters) . '#element-tt_content-' . $row['uid'];
1540
1541 $out .= '<a class="btn btn-default" href="' . htmlspecialchars($url)
1542 . '" title="' . htmlspecialchars($this->nextThree > 1
1543 ? sprintf($this->getLanguageService()->getLL('nextThree'), $this->nextThree)
1544 : $this->getLanguageService()->getLL('edit'))
1545 . '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1546 // Hide element:
1547 $hiddenField = $GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'];
1548 if ($hiddenField && $GLOBALS['TCA']['tt_content']['columns'][$hiddenField]
1549 && (!$GLOBALS['TCA']['tt_content']['columns'][$hiddenField]['exclude']
1550 || $this->getBackendUser()->check('non_exclude_fields', 'tt_content:' . $hiddenField))
1551 ) {
1552 if ($row[$hiddenField]) {
1553 $value = 0;
1554 $label = 'unHide';
1555 } else {
1556 $value = 1;
1557 $label = 'hide';
1558 }
1559 $params = '&data[tt_content][' . ($row['_ORIG_uid'] ? $row['_ORIG_uid'] : $row['uid'])
1560 . '][' . $hiddenField . ']=' . $value;
1561 $out .= '<a class="btn btn-default" href="' . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params))
1562 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL($label)) . '">'
1563 . $this->iconFactory->getIcon('actions-edit-' . strtolower($label), Icon::SIZE_SMALL)->render() . '</a>';
1564 }
1565 // Delete
1566 $params = '&cmd[tt_content][' . $row['uid'] . '][delete]=1';
1567 $confirm = $this->getLanguageService()->getLL('deleteWarning')
1568 . BackendUtility::translationCount('tt_content', $row['uid'], (' '
1569 . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.translationsOfRecord')));
1570 $out .= '<a class="btn btn-default t3js-modal-trigger" href="' . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params)) . '"'
1571 . ' data-severity="warning"'
1572 . ' data-title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_alt_doc.xlf:label.confirm.delete_record.title')) . '"'
1573 . ' data-content="' . htmlspecialchars($confirm) . '" '
1574 . ' data-button-close-text="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:cancel')) . '"'
1575 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('deleteItem')) . '">'
1576 . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render() . '</a>';
1577 if ($out && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)) {
1578 $out = '<div class="btn-group btn-group-sm" role="group">' . $out . '</div>';
1579 } else {
1580 $out = '';
1581 }
1582 if (!$disableMoveAndNewButtons) {
1583 $moveButtonContent = '';
1584 $displayMoveButtons = false;
1585 // Move element up:
1586 if ($this->tt_contentData['prev'][$row['uid']]) {
1587 $params = '&cmd[tt_content][' . $row['uid'] . '][move]=' . $this->tt_contentData['prev'][$row['uid']];
1588 $moveButtonContent .= '<a class="btn btn-default" href="'
1589 . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params))
1590 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveUp')) . '">'
1591 . $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render() . '</a>';
1592 if (!$dragDropEnabled) {
1593 $displayMoveButtons = true;
1594 }
1595 } else {
1596 $moveButtonContent .= '<span class="btn btn-default disabled">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
1597 }
1598 // Move element down:
1599 if ($this->tt_contentData['next'][$row['uid']]) {
1600 $params = '&cmd[tt_content][' . $row['uid'] . '][move]= ' . $this->tt_contentData['next'][$row['uid']];
1601 $moveButtonContent .= '<a class="btn btn-default" href="'
1602 . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params))
1603 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveDown')) . '">'
1604 . $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render() . '</a>';
1605 if (!$dragDropEnabled) {
1606 $displayMoveButtons = true;
1607 }
1608 } else {
1609 $moveButtonContent .= '<span class="btn btn-default disabled">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
1610 }
1611 if ($displayMoveButtons) {
1612 $out .= '<div class="btn-group btn-group-sm" role="group">' . $moveButtonContent . '</div>';
1613 }
1614 }
1615 }
1616 }
1617 $allowDragAndDrop = $this->isDragAndDropAllowed($row);
1618 $additionalIcons = [];
1619 if ($row['sys_language_uid'] > 0 && $this->checkIfTranslationsExistInLanguage([], (int)$row['sys_language_uid'])) {
1620 $disabledClickMenuItems = 'new,move';
1621 $allowDragAndDrop = false;
1622 }
1623 $additionalIcons[] = $this->getIcon('tt_content', $row, $disabledClickMenuItems) . ' ';
1624 $additionalIcons[] = $langMode ? $this->languageFlag($row['sys_language_uid'], false) : '';
1625 // Get record locking status:
1626 if ($lockInfo = BackendUtility::isRecordLocked('tt_content', $row['uid'])) {
1627 $additionalIcons[] = '<a href="#" onclick="alert(' . GeneralUtility::quoteJSvalue($lockInfo['msg'])
1628 . ');return false;" title="' . htmlspecialchars($lockInfo['msg']) . '">'
1629 . $this->iconFactory->getIcon('status-warning-in-use', Icon::SIZE_SMALL)->render() . '</a>';
1630 }
1631 // Call stats information hook
1632 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'])) {
1633 $_params = ['tt_content', $row['uid'], &$row];
1634 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef) {
1635 $additionalIcons[] = GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1636 }
1637 }
1638 // Wrap the whole header
1639 // NOTE: end-tag for <div class="t3-page-ce-body"> is in getTable_tt_content()
1640 return '<div class="t3-page-ce-header ' . ($allowDragAndDrop ? 't3-page-ce-header-draggable t3js-page-ce-draghandle' : '') . '">
1641 <div class="t3-page-ce-header-icons-left">' . implode('', $additionalIcons) . '</div>
1642 <div class="t3-page-ce-header-icons-right">' . ($out ? '<div class="btn-toolbar">' . $out . '</div>' : '') . '</div>
1643 </div>
1644 <div class="t3-page-ce-body">';
1645 }
1646
1647 /**
1648 * Determine whether Drag & Drop should be allowed
1649 *
1650 * @param array $row
1651 * @return bool
1652 */
1653 protected function isDragAndDropAllowed(array $row)
1654 {
1655 if ($this->getBackendUser()->user['admin']
1656 || ((int)$row['editlock'] === 0 && (int)$this->pageinfo['editlock'] === 0)
1657 && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)
1658 && $this->getBackendUser()->checkAuthMode('tt_content', 'CType', $row['CType'], $GLOBALS['TYPO3_CONF_VARS']['BE']['explicitADmode'])
1659 ) {
1660 return true;
1661 }
1662 return false;
1663 }
1664
1665 /**
1666 * Draws the preview content for a content element
1667 *
1668 * @param array $row Content element
1669 * @return string HTML
1670 * @throws \UnexpectedValueException
1671 */
1672 public function tt_content_drawItem($row)
1673 {
1674 $out = '';
1675 $outHeader = '';
1676 // Make header:
1677
1678 if ($row['header']) {
1679 $infoArr = [];
1680 $this->getProcessedValue('tt_content', 'header_position,header_layout,header_link', $row, $infoArr);
1681 $hiddenHeaderNote = '';
1682 // If header layout is set to 'hidden', display an accordant note:
1683 if ($row['header_layout'] == 100) {
1684 $hiddenHeaderNote = ' <em>[' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.hidden')) . ']</em>';
1685 }
1686 $outHeader = $row['date']
1687 ? htmlspecialchars($this->itemLabels['date'] . ' ' . BackendUtility::date($row['date'])) . '<br />'
1688 : '';
1689 $outHeader .= '<strong>' . $this->linkEditContent($this->renderText($row['header']), $row)
1690 . $hiddenHeaderNote . '</strong><br />';
1691 }
1692 // Make content:
1693 $infoArr = [];
1694 $drawItem = true;
1695 // Hook: Render an own preview of a record
1696 $drawItemHooks = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'];
1697 if (is_array($drawItemHooks)) {
1698 foreach ($drawItemHooks as $hookClass) {
1699 $hookObject = GeneralUtility::getUserObj($hookClass);
1700 if (!$hookObject instanceof PageLayoutViewDrawItemHookInterface) {
1701 throw new \UnexpectedValueException($hookClass . ' must implement interface ' . PageLayoutViewDrawItemHookInterface::class, 1218547409);
1702 }
1703 $hookObject->preProcess($this, $drawItem, $outHeader, $out, $row);
1704 }
1705 }
1706
1707 // If the previous hook did not render something,
1708 // then check if a Fluid-based preview template was defined for this CType
1709 // and render it via Fluid. Possible option:
1710 // mod.web_layout.tt_content.preview.media = EXT:site_mysite/Resources/Private/Templates/Preview/Media.html
1711 if ($drawItem) {
1712 $tsConfig = BackendUtility::getModTSconfig($row['pid'], 'mod.web_layout.tt_content.preview');
1713 if (!empty($tsConfig['properties'][$row['CType']])) {
1714 $fluidTemplateFile = $tsConfig['properties'][$row['CType']];
1715 $fluidTemplateFile = GeneralUtility::getFileAbsFileName($fluidTemplateFile);
1716 if ($fluidTemplateFile) {
1717 try {
1718 /** @var StandaloneView $view */
1719 $view = GeneralUtility::makeInstance(StandaloneView::class);
1720 $view->setTemplatePathAndFilename($fluidTemplateFile);
1721 $view->assignMultiple($row);
1722 if (!empty($row['pi_flexform'])) {
1723 /** @var FlexFormService $flexFormService */
1724 $flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
1725 $view->assign('pi_flexform_transformed', $flexFormService->convertFlexFormContentToArray($row['pi_flexform']));
1726 }
1727 $out = $view->render();
1728 $drawItem = false;
1729 } catch (\Exception $e) {
1730 // Catch any exception to avoid breaking the view
1731 }
1732 }
1733 }
1734 }
1735
1736 // Draw preview of the item depending on its CType (if not disabled by previous hook):
1737 if ($drawItem) {
1738 switch ($row['CType']) {
1739 case 'header':
1740 if ($row['subheader']) {
1741 $out .= $this->linkEditContent($this->renderText($row['subheader']), $row) . '<br />';
1742 }
1743 break;
1744 case 'bullets':
1745 case 'table':
1746 if ($row['bodytext']) {
1747 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1748 }
1749 break;
1750 case 'uploads':
1751 if ($row['media']) {
1752 $out .= $this->linkEditContent($this->getThumbCodeUnlinked($row, 'tt_content', 'media'), $row) . '<br />';
1753 }
1754 break;
1755 case 'menu':
1756 $contentType = $this->CType_labels[$row['CType']];
1757 $out .= $this->linkEditContent('<strong>' . htmlspecialchars($contentType) . '</strong>', $row) . '<br />';
1758 // Add Menu Type
1759 $menuTypeLabel = $this->getLanguageService()->sL(
1760 BackendUtility::getLabelFromItemListMerged($row['pid'], 'tt_content', 'menu_type', $row['menu_type'])
1761 );
1762 $menuTypeLabel = $menuTypeLabel ?: 'invalid menu type';
1763 $out .= $this->linkEditContent($menuTypeLabel, $row);
1764 if ($row['menu_type'] !== '2' && ($row['pages'] || $row['selected_categories'])) {
1765 // Show pages if menu type is not "Sitemap"
1766 $out .= ':' . $this->linkEditContent($this->generateListForCTypeMenu($row), $row) . '<br />';
1767 }
1768 break;
1769 case 'shortcut':
1770 if (!empty($row['records'])) {
1771 $shortcutContent = [];
1772 $recordList = explode(',', $row['records']);
1773 foreach ($recordList as $recordIdentifier) {
1774 $split = BackendUtility::splitTable_Uid($recordIdentifier);
1775 $tableName = empty($split[0]) ? 'tt_content' : $split[0];
1776 $shortcutRecord = BackendUtility::getRecord($tableName, $split[1]);
1777 if (is_array($shortcutRecord)) {
1778 $icon = $this->iconFactory->getIconForRecord($tableName, $shortcutRecord, Icon::SIZE_SMALL)->render();
1779 $icon = BackendUtility::wrapClickMenuOnIcon(
1780 $icon,
1781 $tableName,
1782 $shortcutRecord['uid'],
1783 1,
1784 '',
1785 '+copy,info,edit,view'
1786 );
1787 $shortcutContent[] = $icon
1788 . htmlspecialchars(BackendUtility::getRecordTitle($tableName, $shortcutRecord));
1789 }
1790 }
1791 $out .= implode('<br />', $shortcutContent) . '<br />';
1792 }
1793 break;
1794 case 'list':
1795 $hookArr = [];
1796 $hookOut = '';
1797 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$row['list_type']])) {
1798 $hookArr = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$row['list_type']];
1799 } elseif (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info']['_DEFAULT'])) {
1800 $hookArr = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info']['_DEFAULT'];
1801 }
1802 if (!empty($hookArr)) {
1803 $_params = ['pObj' => &$this, 'row' => $row, 'infoArr' => $infoArr];
1804 foreach ($hookArr as $_funcRef) {
1805 $hookOut .= GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1806 }
1807 }
1808 if ((string)$hookOut !== '') {
1809 $out .= $hookOut;
1810 } elseif (!empty($row['list_type'])) {
1811 $label = BackendUtility::getLabelFromItemListMerged($row['pid'], 'tt_content', 'list_type', $row['list_type']);
1812 if (!empty($label)) {
1813 $out .= $this->linkEditContent('<strong>' . htmlspecialchars($this->getLanguageService()->sL($label)) . '</strong>', $row) . '<br />';
1814 } else {
1815 $message = sprintf($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.noMatchingValue'), $row['list_type']);
1816 $out .= '<span class="label label-warning">' . htmlspecialchars($message) . '</span>';
1817 }
1818 } elseif (!empty($row['select_key'])) {
1819 $out .= htmlspecialchars($this->getLanguageService()->sL(BackendUtility::getItemLabel('tt_content', 'select_key')))
1820 . ' ' . $row['select_key'] . '<br />';
1821 } else {
1822 $out .= '<strong>' . $this->getLanguageService()->getLL('noPluginSelected') . '</strong>';
1823 }
1824 $out .= htmlspecialchars($this->getLanguageService()->sL(
1825 BackendUtility::getLabelFromItemlist('tt_content', 'pages', $row['pages'])
1826 )) . '<br />';
1827 break;
1828 default:
1829 $contentType = $this->CType_labels[$row['CType']];
1830
1831 if (isset($contentType)) {
1832 $out .= $this->linkEditContent('<strong>' . htmlspecialchars($contentType) . '</strong>', $row) . '<br />';
1833 if ($row['bodytext']) {
1834 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1835 }
1836 if ($row['image']) {
1837 $out .= $this->linkEditContent($this->getThumbCodeUnlinked($row, 'tt_content', 'image'), $row) . '<br />';
1838 }
1839 } else {
1840 $message = sprintf(
1841 $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.noMatchingValue'),
1842 $row['CType']
1843 );
1844 $out .= '<span class="label label-warning">' . htmlspecialchars($message) . '</span>';
1845 }
1846 }
1847 }
1848 // Wrap span-tags:
1849 $out = '
1850 <span class="exampleContent">' . $out . '</span>';
1851 // Add header:
1852 $out = $outHeader . $out;
1853 // Return values:
1854 if ($this->isDisabled('tt_content', $row)) {
1855 return '<span class="text-muted">' . $out . '</span>';
1856 } else {
1857 return $out;
1858 }
1859 }
1860
1861 /**
1862 * Generates a list of selected pages or categories for the CType menu
1863 *
1864 * @param array $row row from pages
1865 * @return string
1866 */
1867 protected function generateListForCTypeMenu(array $row)
1868 {
1869 $table = 'pages';
1870 $field = 'pages';
1871 // get categories instead of pages
1872 if (strpos($row['menu_type'], 'categorized_') !== false) {
1873 $table = 'sys_category';
1874 $field = 'selected_categories';
1875 }
1876 if (trim($row[$field]) === '') {
1877 return '';
1878 }
1879 $content = '';
1880 $uidList = explode(',', $row[$field]);
1881 foreach ($uidList as $uid) {
1882 $uid = (int)$uid;
1883 $record = BackendUtility::getRecord($table, $uid, 'title');
1884 $content .= '<br>' . $record['title'] . ' (' . $uid . ')';
1885 }
1886 return $content;
1887 }
1888
1889 /**
1890 * Filters out all tt_content uids which are already translated so only non-translated uids is left.
1891 * Selects across columns, but within in the same PID. Columns are expect to be the same
1892 * for translations and original but this may be a conceptual error (?)
1893 *
1894 * @param array $defaultLanguageUids Numeric array with uids of tt_content elements in the default language
1895 * @param int $id Page pid
1896 * @param int $lP Sys language UID
1897 * @return array Modified $defLanguageCount
1898 */
1899 public function getNonTranslatedTTcontentUids($defaultLanguageUids, $id, $lP)
1900 {
1901 if ($lP && !empty($defaultLanguageUids)) {
1902 // Select all translations here:
1903 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
1904 ->getQueryBuilderForTable('tt_content');
1905 $queryBuilder->getRestrictions()
1906 ->removeAll()
1907 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
1908 $queryBuilder
1909 ->select('*')
1910 ->from('tt_content')
1911 ->where(
1912 $queryBuilder->expr()->eq('sys_language_uid', intval($lP)),
1913 $queryBuilder->expr()->in('l18n_parent', array_map('intval', $defaultLanguageUids))
1914 );
1915
1916 $result = $queryBuilder->execute();
1917
1918 // Flip uids:
1919 $defaultLanguageUids = array_flip($defaultLanguageUids);
1920 // Traverse any selected elements and unset original UID if any:
1921 while ($row = $result->fetch()) {
1922 BackendUtility::workspaceOL('tt_content', $row);
1923 unset($defaultLanguageUids[$row['l18n_parent']]);
1924 }
1925 // Flip again:
1926 $defaultLanguageUids = array_keys($defaultLanguageUids);
1927 }
1928 return $defaultLanguageUids;
1929 }
1930
1931 /**
1932 * Creates button which is used to create copies of records..
1933 *
1934 * @param array $defaultLanguageUids Numeric array with uids of tt_content elements in the default language
1935 * @param int $lP Sys language UID
1936 * @param int $colPos Column position
1937 * @return string "Copy languages" button, if available.
1938 */
1939 public function newLanguageButton($defaultLanguageUids, $lP, $colPos = 0)
1940 {
1941 $lP = (int)$lP;
1942 if (!$this->doEdit || !$lP) {
1943 return '';
1944 }
1945 $theNewButton = '';
1946
1947 $allowCopy = true;
1948 $allowTranslate = true;
1949 if (!empty($this->languageHasTranslationsCache[$lP])) {
1950 if (isset($this->languageHasTranslationsCache[$lP]['hasStandAloneContent'])) {
1951 $allowTranslate = false;
1952 }
1953 if (isset($this->languageHasTranslationsCache[$lP]['hasTranslations'])) {
1954 $allowCopy = false;
1955 }
1956 }
1957
1958 if (isset($this->contentElementCache[$lP][$colPos]) && is_array($this->contentElementCache[$lP][$colPos])) {
1959 foreach ($this->contentElementCache[$lP][$colPos] as $record) {
1960 $key = array_search($record['t3_origuid'], $defaultLanguageUids);
1961 if ($key !== false) {
1962 unset($defaultLanguageUids[$key]);
1963 }
1964 }
1965 }
1966
1967 if (!empty($defaultLanguageUids)) {
1968 $theNewButton =
1969 '<input'
1970 . ' class="btn btn-default t3js-localize"'
1971 . ' type="button"'
1972 . ' disabled'
1973 . ' value="' . htmlspecialchars($this->getLanguageService()->getLL('newPageContent_translate')) . '"'
1974 . ' data-has-elements="' . (int)!empty($this->contentElementCache[$lP][$colPos]) . '"'
1975 . ' data-allow-copy="' . (int)$allowCopy . '"'
1976 . ' data-allow-translate="' . (int)$allowTranslate . '"'
1977 . ' data-table="tt_content"'
1978 . ' data-page-id="' . (int)GeneralUtility::_GP('id') . '"'
1979 . ' data-language-id="' . $lP . '"'
1980 . ' data-language-name="' . htmlspecialchars($this->tt_contentConfig['languageCols'][$lP]) . '"'
1981 . ' data-colpos-id="' . $colPos . '"'
1982 . ' data-colpos-name="' . BackendUtility::getProcessedValue('tt_content', 'colPos', $colPos) . '"'
1983 . '/>';
1984 }
1985
1986 return '<div class="t3-page-lang-copyce">' . $theNewButton . '</div>';
1987 }
1988
1989 /**
1990 * Creates onclick-attribute content for a new content element
1991 *
1992 * @param int $id Page id where to create the element.
1993 * @param int $colPos Preset: Column position value
1994 * @param int $sys_language Preset: Sys langauge value
1995 * @return string String for onclick attribute.
1996 * @see getTable_tt_content()
1997 */
1998 public function newContentElementOnClick($id, $colPos, $sys_language)
1999 {
2000 if ($this->option_newWizard) {
2001 $tsConfig = BackendUtility::getModTSconfig($id, 'mod');
2002 $moduleName = isset($tsConfig['properties']['newContentElementWizard.']['override'])
2003 ? $tsConfig['properties']['newContentElementWizard.']['override']
2004 : 'new_content_element';
2005 $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl($moduleName) . '&id=' . $id . '&colPos=' . $colPos
2006 . '&sys_language_uid=' . $sys_language . '&uid_pid=' . $id
2007 . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'))) . ';';
2008 } else {
2009 $onClick = BackendUtility::editOnClick('&edit[tt_content][' . $id . ']=new&defVals[tt_content][colPos]='
2010 . $colPos . '&defVals[tt_content][sys_language_uid]=' . $sys_language);
2011 }
2012 return $onClick;
2013 }
2014
2015 /**
2016 * Will create a link on the input string and possibly a big button after the string which links to editing in the RTE.
2017 * Used for content element content displayed so the user can click the content / "Edit in Rich Text Editor" button
2018 *
2019 * @param string $str String to link. Must be prepared for HTML output.
2020 * @param array $row The row.
2021 * @return string If the whole thing was editable ($this->doEdit) $str is return with link around. Otherwise just $str.
2022 * @see getTable_tt_content()
2023 */
2024 public function linkEditContent($str, $row)
2025 {
2026 if ($this->doEdit && $this->getBackendUser()->recordEditAccessInternals('tt_content', $row)) {
2027 $urlParameters = [
2028 'edit' => [
2029 'tt_content' => [
2030 $row['uid'] => 'edit'
2031 ]
2032 ],
2033 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
2034 ];
2035 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
2036 // Return link
2037 return '<a href="' . htmlspecialchars($url) . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('edit')) . '">' . $str . '</a>';
2038 } else {
2039 return $str;
2040 }
2041 }
2042
2043 /**
2044 * Make selector box for creating new translation in a language
2045 * Displays only languages which are not yet present for the current page and
2046 * that are not disabled with page TS.
2047 *
2048 * @param int $id Page id for which to create a new language (pages_language_overlay record)
2049 * @return string <select> HTML element (if there were items for the box anyways...)
2050 * @see getTable_tt_content()
2051 */
2052 public function languageSelector($id)
2053 {
2054 if ($this->getBackendUser()->check('tables_modify', 'pages_language_overlay')) {
2055 // First, select all
2056 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
2057 $queryBuilder->getRestrictions()->removeAll();
2058 $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(HiddenRestriction::class));
2059 $statement = $queryBuilder->select('uid', 'title')
2060 ->from('sys_language')
2061 ->orderBy('sorting')
2062 ->execute();
2063 $langSelItems = [];
2064 $langSelItems[0] = '
2065 <option value="0"></option>';
2066 while ($row = $statement->fetch()) {
2067 if ($this->getBackendUser()->checkLanguageAccess($row['uid'])) {
2068 $langSelItems[$row['uid']] = '
2069 <option value="' . $row['uid'] . '">' . htmlspecialchars($row['title']) . '</option>';
2070 }
2071 }
2072 // Then, subtract the languages which are already on the page:
2073 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
2074 $queryBuilder->getRestrictions()->removeAll();
2075 $queryBuilder->select('sys_language.uid AS uid', 'sys_language.title AS title')
2076 ->from('sys_language')
2077 ->join(
2078 'sys_language',
2079 'pages_language_overlay',
2080 'pages_language_overlay',
2081 $queryBuilder->expr()->eq('sys_language.uid', $queryBuilder->quoteIdentifier('pages_language_overlay.sys_language_uid'))
2082 )
2083 ->where(
2084 $queryBuilder->expr()->eq('pages_language_overlay.deleted', 0),
2085 $queryBuilder->expr()->eq('pages_language_overlay.pid', (int)$this->id),
2086 $queryBuilder->expr()->orX(
2087 $queryBuilder->expr()->gte('pages_language_overlay.t3ver_state', (int)(new VersionState(VersionState::DEFAULT_STATE))),
2088 $queryBuilder->expr()->eq('pages_language_overlay.t3ver_wsid', (int)$this->getBackendUser()->workspace)
2089 )
2090 )
2091 ->groupBy('pages_language_overlay.sys_language_uid', 'sys_language.uid', 'sys_language.pid',
2092 'sys_language.tstamp', 'sys_language.hidden', 'sys_language.title',
2093 'sys_language.language_isocode', 'sys_language.static_lang_isocode', 'sys_language.flag')
2094 ->orderBy('sys_language.sorting');
2095 if (!$this->getBackendUser()->isAdmin()) {
2096 $queryBuilder->andWhere($queryBuilder->expr()->eq('sys_language.hidden', 0));
2097 }
2098 $statement = $queryBuilder->execute();
2099 while ($row = $statement->fetch()) {
2100 unset($langSelItems[$row['uid']]);
2101 }
2102 // Remove disallowed languages
2103 if (count($langSelItems) > 1
2104 && !$this->getBackendUser()->user['admin']
2105 && $this->getBackendUser()->groupData['allowed_languages'] !== ''
2106 ) {
2107 $allowed_languages = array_flip(explode(',', $this->getBackendUser()->groupData['allowed_languages']));
2108 if (!empty($allowed_languages)) {
2109 foreach ($langSelItems as $key => $value) {
2110 if (!isset($allowed_languages[$key]) && $key != 0) {
2111 unset($langSelItems[$key]);
2112 }
2113 }
2114 }
2115 }
2116 // Remove disabled languages
2117 $modSharedTSconfig = BackendUtility::getModTSconfig($id, 'mod.SHARED');
2118 $disableLanguages = isset($modSharedTSconfig['properties']['disableLanguages'])
2119 ? GeneralUtility::trimExplode(',', $modSharedTSconfig['properties']['disableLanguages'], true)
2120 : [];
2121 if (!empty($langSelItems) && !empty($disableLanguages)) {
2122 foreach ($disableLanguages as $language) {
2123 if ($language != 0 && isset($langSelItems[$language])) {
2124 unset($langSelItems[$language]);
2125 }
2126 }
2127 }
2128 // If any languages are left, make selector:
2129 if (count($langSelItems) > 1) {
2130 $url = BackendUtility::getModuleUrl('record_edit', [
2131 'edit[pages_language_overlay][' . $id . ']' => 'new',
2132 'overrideVals[pages_language_overlay][doktype]' => (int)$this->pageRecord['doktype'],
2133 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
2134 ]);
2135 $onChangeContent = 'window.location.href=' . GeneralUtility::quoteJSvalue($url . '&overrideVals[pages_language_overlay][sys_language_uid]=') . '+this.options[this.selectedIndex].value';
2136 return '<div class="form-inline form-inline-spaced">'
2137 . '<div class="form-group">'
2138 . '<label for="createNewLanguage">'
2139 . htmlspecialchars($this->getLanguageService()->getLL('new_language'))
2140 . '</label>'
2141 . '<select class="form-control input-sm" name="createNewLanguage" onchange="' . htmlspecialchars($onChangeContent) . '">'
2142 . implode('', $langSelItems)
2143 . '</select></div></div>';
2144 }
2145 }
2146 return '';
2147 }
2148
2149 /**
2150 * Traverse the result pointer given, adding each record to array and setting some internal values at the same time.
2151 *
2152 * @param \Doctrine\DBAL\Driver\Statement $result MySQLi result object / DBAL object
2153 * @param string $table Table name defaulting to tt_content
2154 * @return array The selected rows returned in this array.
2155 */
2156 public function getResult(\Doctrine\DBAL\Driver\Statement $result, string $table = 'tt_content'): array
2157 {
2158 $output = [];
2159 // Traverse the result:
2160 while ($row = $result->fetch()) {
2161 BackendUtility::workspaceOL($table, $row, -99, true);
2162 if ($row) {
2163 // Add the row to the array:
2164 $output[] = $row;
2165 }
2166 }
2167 $this->generateTtContentDataArray($output);
2168 // Return selected records
2169 return $output;
2170 }
2171
2172 /********************************
2173 *
2174 * Various helper functions
2175 *
2176 ********************************/
2177
2178 /**
2179 * Initializes the clipboard for generating paste links
2180 *
2181 * @return void
2182 *
2183 * @see \TYPO3\CMS\Recordlist\RecordList::main()
2184 * @see \TYPO3\CMS\Backend\Controller\ClickMenuController::main()
2185 * @see \TYPO3\CMS\Filelist\Controller\FileListController::main()
2186 */
2187 protected function initializeClipboard()
2188 {
2189 // Start clipboard
2190 $this->clipboard = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Clipboard\Clipboard::class);
2191
2192 // Initialize - reads the clipboard content from the user session
2193 $this->clipboard->initializeClipboard();
2194
2195 // This locks the clipboard to the Normal for this request.
2196 $this->clipboard->lockToNormal();
2197
2198 // Clean up pad
2199 $this->clipboard->cleanCurrent();
2200
2201 // Save the clipboard content
2202 $this->clipboard->endClipboard();
2203 }
2204
2205 /**
2206 * Generates the data for previous and next elements which is needed for movements.
2207 *
2208 * @param array $rowArray
2209 * @return void
2210 */
2211 protected function generateTtContentDataArray(array $rowArray)
2212 {
2213 if (empty($this->tt_contentData)) {
2214 $this->tt_contentData = [
2215 'nextThree' => [],
2216 'next' => [],
2217 'prev' => [],
2218 ];
2219 }
2220 foreach ($rowArray as $key => $value) {
2221 // Create the list of the next three ids (for editing links...)
2222 for ($i = 0; $i < $this->nextThree; $i++) {
2223 if (isset($rowArray[$key - $i])
2224 && !GeneralUtility::inList($this->tt_contentData['nextThree'][$rowArray[$key - $i]['uid']], $value['uid'])
2225 ) {
2226 $this->tt_contentData['nextThree'][$rowArray[$key - $i]['uid']] .= $value['uid'] . ',';
2227 }
2228 }
2229
2230 // Create information for next and previous content elements
2231 if (isset($rowArray[$key - 1])) {
2232 if (isset($rowArray[$key - 2])) {
2233 $this->tt_contentData['prev'][$value['uid']] = -$rowArray[$key - 2]['uid'];
2234 } else {
2235 $this->tt_contentData['prev'][$value['uid']] = $value['pid'];
2236 }
2237 $this->tt_contentData['next'][$rowArray[$key - 1]['uid']] = -$value['uid'];
2238 }
2239 }
2240 }
2241
2242 /**
2243 * Counts and returns the number of records on the page with $pid
2244 *
2245 * @param string $table Table name
2246 * @param int $pid Page id
2247 * @return int Number of records.
2248 */
2249 public function numberOfRecords($table, $pid)
2250 {
2251 $count = 0;
2252 if ($GLOBALS['TCA'][$table]) {
2253 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
2254 ->getQueryBuilderForTable($table);
2255 $queryBuilder->getRestrictions()
2256 ->removeAll()
2257 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
2258 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
2259 $count = (int)$queryBuilder->count('uid')
2260 ->from($table)
2261 ->where($queryBuilder->expr()->eq('pid', (int)$pid))
2262 ->execute()
2263 ->fetchColumn();
2264 }
2265
2266 return $count;
2267 }
2268
2269 /**
2270 * Processing of larger amounts of text (usually from RTE/bodytext fields) with word wrapping etc.
2271 *
2272 * @param string $input Input string
2273 * @return string Output string
2274 */
2275 public function renderText($input)
2276 {
2277 $input = strip_tags($input);
2278 $input = GeneralUtility::fixed_lgd_cs($input, 1500);
2279 return nl2br(htmlspecialchars(trim($input), ENT_QUOTES, 'UTF-8', false));
2280 }
2281
2282 /**
2283 * Creates the icon image tag for record from table and wraps it in a link which will trigger the click menu.
2284 *
2285 * @param string $table Table name
2286 * @param array $row Record array
2287 * @param string $enabledClickMenuItems Passthrough to wrapClickMenuOnIcon
2288 * @return string HTML for the icon
2289 */
2290 public function getIcon($table, $row, $enabledClickMenuItems = '')
2291 {
2292 // Initialization
2293 $toolTip = BackendUtility::getRecordToolTip($row, 'tt_content');
2294 $icon = '<span ' . $toolTip . '>' . $this->iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render() . '</span>';
2295 $this->counter++;
2296 // The icon with link
2297 if ($this->getBackendUser()->recordEditAccessInternals($table, $row)) {
2298 $icon = BackendUtility::wrapClickMenuOnIcon($icon, $table, $row['uid'], true, '', $enabledClickMenuItems);
2299 }
2300 return $icon;
2301 }
2302
2303 /**
2304 * Creates processed values for all field names in $fieldList based on values from $row array.
2305 * The result is 'returned' through $info which is passed as a reference
2306 *
2307 * @param string $table Table name
2308 * @param string $fieldList Comma separated list of fields.
2309 * @param array $row Record from which to take values for processing.
2310 * @param array $info Array to which the processed values are added.
2311 * @return void
2312 */
2313 public function getProcessedValue($table, $fieldList, array $row, array &$info)
2314 {
2315 // Splitting values from $fieldList
2316 $fieldArr = explode(',', $fieldList);
2317 // Traverse fields from $fieldList
2318 foreach ($fieldArr as $field) {
2319 if ($row[$field]) {
2320 $info[] = '<strong>' . htmlspecialchars($this->itemLabels[$field]) . '</strong> '
2321 . htmlspecialchars(BackendUtility::getProcessedValue($table, $field, $row[$field]));
2322 }
2323 }
2324 }
2325
2326 /**
2327 * Returns TRUE, if the record given as parameters is NOT visible based on hidden/starttime/endtime (if available)
2328 *
2329 * @param string $table Tablename of table to test
2330 * @param array $row Record row.
2331 * @return bool Returns TRUE, if disabled.
2332 */
2333 public function isDisabled($table, $row)
2334 {
2335 $enableCols = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
2336 return $enableCols['disabled'] && $row[$enableCols['disabled']]
2337 || $enableCols['starttime'] && $row[$enableCols['starttime']] > $GLOBALS['EXEC_TIME']
2338 || $enableCols['endtime'] && $row[$enableCols['endtime']] && $row[$enableCols['endtime']] < $GLOBALS['EXEC_TIME'];
2339 }
2340
2341 /**
2342 * Returns icon for "no-edit" of a record.
2343 * Basically, the point is to signal that this record could have had an edit link if
2344 * the circumstances were right. A placeholder for the regular edit icon...
2345 *
2346 * @param string $label Label key from LOCAL_LANG
2347 * @return string IMG tag for icon.
2348 */
2349 public function noEditIcon($label = 'noEditItems')
2350 {
2351 $title = htmlspecialchars($this->getLanguageService()->getLL($label));
2352 return '<span title="' . $title . '">' . $this->iconFactory->getIcon('status-status-edit-read-only', Icon::SIZE_SMALL)->render() . '</span>';
2353 }
2354
2355 /**
2356 * Function, which fills in the internal array, $this->allowedTableNames with all tables to
2357 * which the user has access. Also a set of standard tables (pages, static_template, sys_filemounts, etc...)
2358 * are filtered out. So what is left is basically all tables which makes sense to list content from.
2359 *
2360 * @return array
2361 */
2362 protected function cleanTableNames()
2363 {
2364 // Get all table names:
2365 $tableNames = array_flip(array_keys($GLOBALS['TCA']));
2366 // Unset common names:
2367 unset($tableNames['pages']);
2368 unset($tableNames['static_template']);
2369 unset($tableNames['sys_filemounts']);
2370 unset($tableNames['sys_action']);
2371 unset($tableNames['sys_workflows']);
2372 unset($tableNames['be_users']);
2373 unset($tableNames['be_groups']);
2374 $allowedTableNames = [];
2375 // Traverse table names and set them in allowedTableNames array IF they can be read-accessed by the user.
2376 if (is_array($tableNames)) {
2377 foreach ($tableNames as $k => $v) {
2378 if (!$GLOBALS['TCA'][$k]['ctrl']['hideTable'] && $this->getBackendUser()->check('tables_select', $k)) {
2379 $allowedTableNames['table_' . $k] = $k;
2380 }
2381 }
2382 }
2383 return $allowedTableNames;
2384 }
2385
2386 /*****************************************
2387 *
2388 * External renderings
2389 *
2390 *****************************************/
2391
2392 /**
2393 * Creates a menu of the tables that can be listed by this function
2394 * Only tables which has records on the page will be included.
2395 * Notice: The function also fills in the internal variable $this->activeTables with icon/titles.
2396 *
2397 * @param int $id Page id from which we are listing records (the function will look up if there are records on the page)
2398 * @return string HTML output.
2399 */
2400 public function getTableMenu($id)
2401 {
2402 // Initialize:
2403 $this->activeTables = [];
2404 $theTables = ['tt_content'];
2405 // External tables:
2406 if (is_array($this->externalTables)) {
2407 $theTables = array_unique(array_merge($theTables, array_keys($this->externalTables)));
2408 }
2409 $out = '';
2410 // Traverse tables to check:
2411 foreach ($theTables as $tName) {
2412 // Check access and whether the proper extensions are loaded:
2413 if ($this->getBackendUser()->check('tables_select', $tName)
2414 && (isset($this->externalTables[$tName])
2415 || $tName === 'fe_users' || $tName === 'tt_content'
2416 || \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($tName)
2417 )
2418 ) {
2419 // Make query to count records from page:
2420 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
2421 ->getQueryBuilderForTable($tName);
2422 $queryBuilder->getRestrictions()
2423 ->removeAll()
2424 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
2425 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
2426 $count = $queryBuilder->count('uid')
2427 ->from($tName)
2428 ->where($queryBuilder->expr()->eq('pid', (int)$id))
2429 ->execute()
2430 ->fetchColumn();
2431 // If records were found (or if "tt_content" is the table...):
2432 if ($count || $tName === 'tt_content') {
2433 // Add row to menu:
2434 $out .= '
2435 <td><a href="#' . $tName . '" title="' . htmlspecialchars($this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'])) . '"></a>'
2436 . $this->iconFactory->getIconForRecord($tName, [], Icon::SIZE_SMALL)->render()
2437 . '</td>';
2438 // ... and to the internal array, activeTables we also add table icon and title (for use elsewhere)
2439 $title = htmlspecialchars($this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title']))
2440 . ': ' . $count . ' ' . htmlspecialchars($this->getLanguageService()->getLL('records'));
2441 $this->activeTables[$tName] = '<span title="' . $title . '">'
2442 . $this->iconFactory->getIconForRecord($tName, [], Icon::SIZE_SMALL)->render()
2443 . '</span>'
2444 . '&nbsp;' . htmlspecialchars($this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title']));
2445 }
2446 }
2447 }
2448 // Wrap cells in table tags:
2449 $out = '
2450 <!--
2451 Menu of tables on the page (table menu)
2452 -->
2453 <table border="0" cellpadding="0" cellspacing="0" id="typo3-page-tblMenu">
2454 <tr>' . $out . '
2455 </tr>
2456 </table>';
2457 // Return the content:
2458 return $out;
2459 }
2460
2461 /**
2462 * Create thumbnail code for record/field but not linked
2463 *
2464 * @param mixed[] $row Record array
2465 * @param string $table Table (record is from)
2466 * @param string $field Field name for which thumbnail are to be rendered.
2467 * @return string HTML for thumbnails, if any.
2468 */
2469 public function getThumbCodeUnlinked($row, $table, $field)
2470 {
2471 return BackendUtility::thumbCode($row, $table, $field, '', '', null, 0, '', '', false);
2472 }
2473
2474 /**
2475 * Checks whether translated Content Elements exist in the desired language
2476 * If so, deny creating new ones via the UI
2477 *
2478 * @param array $contentElements
2479 * @param int $language
2480 * @return bool
2481 */
2482 protected function checkIfTranslationsExistInLanguage(array $contentElements, $language)
2483 {
2484 // If in default language, you may always create new entries
2485 // Also, you may override this strict behavior via user TS Config
2486 // If you do so, you're on your own and cannot rely on any support by the TYPO3 core
2487 // We jump out here since we don't need to do the expensive loop operations
2488 $allowInconsistentLanguageHandling = BackendUtility::getModTSconfig($this->id, 'mod.web_layout.allowInconsistentLanguageHandling');
2489 if ($language === 0 || $allowInconsistentLanguageHandling['value'] === '1') {
2490 return false;
2491 }
2492 /**
2493 * Build up caches
2494 */
2495 if (!isset($this->languageHasTranslationsCache[$language])) {
2496 foreach ($contentElements as $columns) {
2497 foreach ($columns as $contentElement) {
2498 if ((int)$contentElement['l18n_parent'] === 0) {
2499 $this->languageHasTranslationsCache[$language]['hasStandAloneContent'] = true;
2500 }
2501 if ((int)$contentElement['l18n_parent'] > 0) {
2502 $this->languageHasTranslationsCache[$language]['hasTranslations'] = true;
2503 }
2504 }
2505 }
2506 // Check whether we have a mix of both
2507 if ($this->languageHasTranslationsCache[$language]['hasStandAloneContent']
2508 && $this->languageHasTranslationsCache[$language]['hasTranslations']
2509 ) {
2510 $message = GeneralUtility::makeInstance(
2511 FlashMessage::class,
2512 sprintf($this->getLanguageService()->getLL('staleTranslationWarning'), $this->languageIconTitles[$language]['title']),
2513 sprintf($this->getLanguageService()->getLL('staleTranslationWarningTitle'), $this->languageIconTitles[$language]['title']),
2514 FlashMessage::WARNING
2515 );
2516 $service = GeneralUtility::makeInstance(FlashMessageService::class);
2517 $queue = $service->getMessageQueueByIdentifier();
2518 $queue->addMessage($message);
2519 }
2520 }
2521 if ($this->languageHasTranslationsCache[$language]['hasTranslations']) {
2522 return true;
2523 }
2524 return false;
2525 }
2526
2527 /**
2528 * @return BackendLayoutView
2529 */
2530 protected function getBackendLayoutView()
2531 {
2532 return GeneralUtility::makeInstance(BackendLayoutView::class);
2533 }
2534
2535 /**
2536 * @return BackendUserAuthentication
2537 */
2538 protected function getBackendUser()
2539 {
2540 return $GLOBALS['BE_USER'];
2541 }
2542
2543 /**
2544 * @return DatabaseConnection
2545 */
2546 protected function getDatabase()
2547 {
2548 return $GLOBALS['TYPO3_DB'];
2549 }
2550
2551 /**
2552 * @return PageLayoutController
2553 */
2554 protected function getPageLayoutController()
2555 {
2556 return $GLOBALS['SOBE'];
2557 }
2558 }