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