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