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