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