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